【发布时间】:2015-06-02 00:19:19
【问题描述】:
我正在尝试使用 XML 字符串请求 REST POST API,但我收到以下错误响应。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<apiErrors>
<apiError>
<errorMessage>415 Unsupported Media Type - null</errorMessage>
</apiError>
</apiErrors>
我不明白为什么会这样。即使我也设置了内容类型和标题。
请看一下我的代码。
String XmlString = "<Contact>"
+"<name>Sandeep</name>"
+"<title>Mr.</title>"
+"<Address>India</Address>"
+"</Contact>";
try {
StringEntity se = new StringEntity(XmlString);
HttpPost httpRequest = new HttpPost("http://abc:xyz123@000.000.000.00:8080/aaa/sample/feed/000001");
httpRequest.setHeader("Content-Type","application/soap-xml;charset=UTF-8");
httpRequest.setHeader("Accept","text/plain");
httpRequest.setEntity(se);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse httpResponse;
httpResponse = httpclient.execute(httpRequest, new BasicHttpContext());
finalres = inputStreamToString(httpResponse.getEntity().getContent())
.toString();
请给我提示或参考。
【问题讨论】:
-
能发下相关网址吗?
-
尝试使用
curl发送您的请求(这是一个 linux 实用程序,google forman curl)。顺便说一句,我在 Accept 中看到text/plain,你不是说 XML 吗? -
你能说一下服务器REST实现的技术是什么吗?你确定服务器应该接受 application/soap-xml 而不是 application/xml?