I am having a api which describes as follow:
Given a typical HTML form as follows:
<form method="post" action="/api">
<input type="hidden" name="action" value="login" />
<input type="hidden" name="username" value="testuser" />
<input type="hidden" name="password" value="123" />
</form>
When the HTML form above is submitted, the following shows an example of how the information can be sent using HTTP protocol:
POST /api HTTP/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 43
action=login&username=testuser&password=123
The system will send back a reply which looks like the following:
HTTP/1.0 200 OK
Content-Type: application/json
{ 'session_token':'a1234aa334567432bccdd001f123450abcedfa0b' }
Can anyone guide me to how am I suppose to retrieve the session token from the post response using android java?
EDIT: (here's some of my code to send and retrieve the request and response.)
HttpPost httpost = new HttpPost("url of server");
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("username","testuser" ));
nvps.add(new BasicNameValuePair("password", "1234567" ));
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
HttpResponse response = getResponse(httpost);
public HttpResponse getResponse(HttpPost httpPost) throws Exception {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httpPost);
return response;
}