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