2
我有其描述如下一個API:如何從httpResponse中檢索會話令牌?
給出一個典型的HTML形式如下:
<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>
當上面的HTML表單提交,下面說明如何 的信息可以的一例使用HTTP協議來發送:
POST /api HTTP/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 43
action=login&username=testuser&password=123
系統將發送回它看起來像下面的答覆:
HTTP/1.0 200 OK
Content-Type: application/json
{ 'session_token':'a1234aa334567432bccdd001f123450abcedfa0b' }
任何人都可以指導我如何我想從使用android java的帖子響應檢索會話令牌?
編輯:(這裏是我的一些代碼來發送和檢索請求和響應。)
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;
}
這個::'http:// www.technotalkative.com/android-json-parsing /'會幫你 –
檢查這個問題:http://stackoverflow.com/questions/6381491/how-to-save-和返回的cookie到了的Web服務 – Ian