Https Request, Authentication In Android
I am currently trying to authenticate with a server via a http Get call. The code provided below works when compiled in a java project. Returning the correct token to the program.
Solution 1:
You probably did not add the Internet-Permission to your projects AndroidManifest.xml.
If so, add the following line as a child of the <manifest/>
node:
<uses-permissionandroid:name="android.permission.INTERNET" />
Solution 2:
I'm using POST and FormEntity for retrieving data from the server (such as authentication), and i have never had any problems:
finalStringhttpsURL="https://the url";
finalDefaultHttpClientclient=newDefaultHttpClient();
finalHttpPosthttppost=newHttpPost(httpsURL);
//authentication block:final List<BasicNameValuePair> nvps = newArrayList<BasicNameValuePair>();
nvps.add(newBasicNameValuePair("userName", userName));
nvps.add(newBasicNameValuePair("password", password));
finalUrlEncodedFormEntityp_entity=newUrlEncodedFormEntity(nvps, HTTP.UTF_8);
httppost.setEntity(p_entity);
//sending the request and retrieving the response:HttpResponseresponse= client.execute(httppost);
HttpEntityresponseEntity= response.getEntity();
//handling the response: responseEntity.getContent() is your InputStreamfinalInputSourceinputSource=newInputSource(responseEntity.getContent());
[...]
maybe you'll find this usefull
Post a Comment for "Https Request, Authentication In Android"