0

为了执行 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 响应。

什么可能导致这个问题?

4

0 回答 0