【发布时间】:2011-11-29 04:28:18
【问题描述】:
我有一个描述如下的 api:
给定一个典型的 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/会帮助你
标签: java android http-post httpresponse