415 XML Post Rest API不受支持的媒体类型 [英] 415 Unsupported Media Type for XML Post Rest API
问题描述
我正在尝试使用XML字符串请求REST POST API,但是我收到以下错误响应.
I am trying to Request for REST POST API with XML string but I am getting following error response.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<apiErrors>
<apiError>
<errorMessage>415 Unsupported Media Type - null</errorMessage>
</apiError>
</apiErrors>
我不明白为什么会这样.甚至我也设置了内容类型和标题.
I don't understand why this happening. Even I set content-type and header also.
请看一下我的代码.
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();
请给我提示或参考.
推荐答案
在您的请求中,您指定的通信为soap-xml
In your request you are specifying the communication to be soap-xml
httpRequest.setHeader("Content-Type","application/soap-xml;charset=UTF-8");
尝试通过删除"soap"部分来指定使用纯xml.
Try to specify to use plain xml by removing the "soap" part.
有效的xml内容类型:
Valid xml content types:
文本/xml"或应用程序/xml"
"text/xml" or "application/xml"
Soap调用是非常特定格式的xml,从响应中看,除非您修剪输出以删除所有soap xml,否则它似乎是纯XML服务.
Soap calls are very specifically formatted xml and from the response, unless you trimmed the output to remove all of the soap xml, it appears to be a plain xml service.
这篇关于415 XML Post Rest API不受支持的媒体类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!