【发布时间】:2013-02-18 11:40:29
【问题描述】:
我需要创建一个带有两个参数的 HttpPost 请求。我同意有很多例子,但我相信我已经完成了我的研究,但我仍然没有得到 ASP 服务器的响应。我已经尝试过 NameValuePair,但似乎无法获得响应页面。我猜这些参数没有被添加到 httpPost 对象中。
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://portal.sibt.nsw.edu.au/Default.asp");
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
nameValuePair.add(new BasicNameValuePair("userID", id.getText().toString()));
nameValuePair.add(new BasicNameValuePair("password", pword.getText().toString()));
post.setEntity(new UrlEncodedFormEntity(nameValuePair));
HttpResponse response = client.execute(post);
String responseContent = EntityUtils.toString(response.getEntity());
Log.d("response to string", responseContent);
我再次进入登录页面,这段代码返回 NullPointerException:
String newURL = response.getFirstHeader("Location").getValue();
我在这里做错了什么?
【问题讨论】:
-
请提交 logcat 以获得更多帮助
标签: java android http-post httpclient