Java 不支持的内容类型:文本/纯文本;字符集=ISO-8859-1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22176769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unsupported content type: text/plain; charset=ISO-8859-1
提问by mrk2
I have a webservice which has to return player details in response. The problem is, when I send same request in SoapUI I get valid response, but when I do this through Java, I get back this message in
我有一个网络服务,它必须返回玩家详细信息作为响应。问题是,当我在 SoapUI 中发送相同的请求时,我得到了有效的响应,但是当我通过 Java 执行此操作时,我会在
<faultstring> Unsupported content type: text/plain; charset=ISO-8859-1 </faultstring>
.
<faultstring> Unsupported content type: text/plain; charset=ISO-8859-1 </faultstring>
.
Any ideas why it is the problem?
任何想法为什么会出现问题?
This is request I am sending:
这是我发送的请求:
> <soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:gen=" ">
> <soapenv:Header/>
> <soapenv:Body>
> <gen:GetPlayerDetails>
> <request>
> <systemUID>C_GS01</systemUID>
> <sessionID>TVM0MgAAB9IAAAFEjXyfxbvZ2oU_</sessionID>
> </request>
> </gen:GetPlayerDetails>
> </soapenv:Body>
> </soapenv:Envelope>
SOLVEDthanks to @helderdarocha Made some changes (last line) in my HTTP client class:
解决由于@helderdarocha改变了我的HTTP客户端类的一些变化(最后一行):
HttpClient httpclient = HttpClientBuilder.create().build();
StringEntity strEntity = new StringEntity(request);
HttpPost post = new HttpPost("http://10.47.44.163:8080" + endPointURI);
post.addHeader("Content-type", "text/xml");
采纳答案by helderdarocha
You are probably sending a request without the appropriate headers. You have to declare the type of data your client accepts as a response using the Accept
header:
您可能正在发送没有适当标头的请求。您必须使用Accept
标头声明客户端接受的数据类型作为响应:
Accept: application/xml; application/json;
Additionally, if you are sending data, you have to declare the Content-type of what you are sending, and it should be compatible with the data your service accepts.
此外,如果您正在发送数据,您必须声明您发送的内容类型,并且它应该与您的服务接受的数据兼容。
Content-type: application/xml
If you are sending payload in XML, for example.
例如,如果您以 XML 格式发送有效负载。