我需要将一些 XML 发送到 web 服务,并且我能够使用普通的 StringEntity 来完成它,因为它只是文本,但现在我还需要将图像附加到它。我尝试使用 MultipartEntity 进行操作,但无法仅使用 XML。
// 在职的
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?