我想在java中爲android發送POST請求。http對android的發佈請求
我用這個代碼:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("myUrl");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("artist", "Amy Macdonald"));
nameValuePairs.add(new BasicNameValuePair("title", "Don't Tell Me That It's Over"));
nameValuePairs.add(new BasicNameValuePair("album", "Don't Tell Me That It's Over"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
的問題是,當我使用:
HttpResponse response = httpclient.execute(httppost);
我得到一個異常,而這個web服務的工作是肯定的,