不支持的内容类型:text/plain; 字符集= ISO-8859-1

mrk*_*rk2 6 java soap web-services soapui

我有一个web服务,必须返回播放器详细信息作为响应.问题是,当我在SoapUI中发送相同的请求时,我得到了有效的响应,但是当我通过Java执行此操作时,我会收到此消息

<faultstring> Unsupported content type: text/plain; charset=ISO-8859-1 </faultstring>.

任何想法为什么会出现问题?

这是我发送的请求:

> <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>
Run Code Online (Sandbox Code Playgroud)

已解决,感谢@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");
Run Code Online (Sandbox Code Playgroud)

hel*_*cha 5

您可能在没有相应标头的情况下发送请求.您必须使用Accept标头声明客户端接受的数据类型作为响应:

Accept: application/xml; application/json;
Run Code Online (Sandbox Code Playgroud)

此外,如果您要发送数据,则必须声明要发送的内容类型,并且它应与您的服务接受的数据兼容.

Content-type: application/xml
Run Code Online (Sandbox Code Playgroud)

例如,如果要以XML格式发送有效负载.