我需要一些XML发送到Web服务,我能够与正常StringEntity这样做,因为它只是文字,但现在我需要的图像附加到它。我试着用MultipartEntity做这件事,但是我不能用它来处理XML。MultipartEntity没有创造良好的请求
//工作
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost doc = new HttpPost("http://mywebservices.com");
HttpEntity entity = new StringEntity(writer.toString());
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity responseEntity = response.getEntity();
//不工作
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost doc = new HttpPost("http://mywebservices.com");
// no difference when removing the BROWSER_COMPATIBLE
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("xml", new StringBody(writer.toString()));
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity responseEntity = response.getEntity();
,是有办法,我可以看到正在发送的MIME?
哦我看到我忘了复制'httppost.setEntity(实体);',它在我的代码,但没有工作:( – 2011-03-29 17:34:34
嗯,你说这是行不通的,究竟是什么出了问题 – 2011-03-30 20:35:49
web服务是?无法读取请求并给我一个错误,所以'MultipartEntity'产生的另一个帖子比正常的'HttpEntity',但我无法看到帖子。 – 2011-03-31 07:55:46