我需要創建一個帶有兩個參數的HttpPost請求。我同意有很多例子,但我相信我已經完成了我的研究,但我仍然沒有從ASP服務器獲得迴應。我試過NameValuePair,但我似乎無法獲得響應頁面。我猜測參數沒有被添加到httpPost對象。HttpPost參數無法工作到ASP服務器
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期待着更多的幫助 – 2013-02-18 11:46:00