为了执行http POST请求,我编写了以下函数:
private void httpPost(final File xmlFile){
String textviewresponse;
Thread thread = new Thread(){
@Override
public void run() {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://myURL");
StringEntity entity;
HttpResponse httpresponse;
try {
entity = new StringEntity(xmlFile.toString());
entity.setContentType("text/xml");
Log.d("TAG",httppost.getURI().toString());
httppost.setEntity(entity);
try {
httpresponse = httpclient.execute(httppost);
textviewresponse=EntityUtils.toString(httpresponse.getEntity());
Log.d("TAG",textviewresponse);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
httpclient.getConnectionManager().shutdown();
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
thread.start();
}
问题在于,当我发送请求时,我会继续获得GET方法的响应,而不是我应该获得的POST。
可能导致此问题的原因是什么?