我需要一些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