我需要创建一个带有两个参数的 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();
我在这里做错了什么?