android - Authenticator response code 400 -
i tried hitting server using httpsurlconnection
, got response code 401 - need authenticate. tried following:
authenticator.setdefault (new authenticator() { protected passwordauthentication getpasswordauthentication() { return new passwordauthentication ("myuser", "!mypassword".tochararray()); } });
got response code 400 - bad request.
based on stackoverflow research tried using:
string authorizationstring = "basic " + base64.encodetostring(("username" + ":" + "password").getbytes(), base64.default); conn.setrequestproperty("authorization", authorizationstring);
same problem, code 400. i'm trusting hosts using @chrispix method in post: trust anchor not found android ssl connection not sure if interfering somehow, prototype , site certificate isn't valid, needed bypass check.
the connection set these properties, not sure if there wrong or missing:
httpsurlconnection conn = (httpsurlconnection) url.openconnection(); conn.setreadtimeout(10000 /* milliseconds */); conn.setconnecttimeout(15000 /* milliseconds */); conn.addrequestproperty("content-type", "application/json"); conn.setrequestmethod("post"); conn.setdoinput(true);
thanks!
how using httpclient
?
httpclient httpclient= new defaulthttpclient(); httpget httpget= new httpget(yoururl); string authstring = (yourusername+":"+yourpassword); httpget.addheader("authorization", "basic " + base64.encodetostring(authstring.getbytes(),base64.default)); httpresponse response = httpclient.execute(httpget);
seems wanna by-pass cert checking currently, related link may you
Comments
Post a Comment