我想在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服务的工作是肯定的,