0

我正在使用 JAva HttpsURLConnection 发送肥皂信封消息。请参阅下面我的肥皂信封有效负载:

OutputStream out = con.getOutputStream();
      Writer wout = new OutputStreamWriter(out);

      wout.write("<?xml version='1.0' encoding='UTF-8'?>\r\n");  
      wout.write("<S:Envelope xmlns:S= ");
      wout.write(
        "'http://schemas.xmlsoap.org/soap/envelope/'>\r\n"
      );
      wout.write("<S:Body><ns2:getAccessibleDBs xmlns:ns2=");
      wout.write(
        "'http://webservice.namespace.com/'>\r\n"); 
      wout.write("  </ns2:getAccessibleDBs>\r\n");
       wout.write("  </S:Body>\r\n"); 
      wout.write("</S:Envelope>\r\n"); 

      wout.flush();
      wout.close();

但是服务器消息如下:

com.sun.xml.ws.transport.http.HttpAdapter E Unsupported Content-Type: application/x-www-form-urlencoded 支持的有:[text/xml] com.sun.xml.ws.server.UnsupportedMediaException: Unsupported Content-Type:application/x-www-form-urlencoded 支持的有:[text/xml]

可以,请您提供有关如何格式化消息paylod以避免服务器错误的见解。

问候,

4

1 回答 1

0

You have two hardles,

  1. You're not setting accurate HTTP Header Content-Type="text/xml" that server is expecting.
  2. Your XML is incorrect. It should be like below, no unnecessary newlines \r\n etc and namespace should start with double quote rather then single quote.

    <xml version="1.0" encoding="UTF-8"?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body><ns2:getAccessibleDBs xmlns:ns2="http://webservice.namespace.com/"> </ns2:getAccessibleDBs></S:Body></S:Envelope>

It should work if you do above two changes.

于 2018-06-30T11:56:21.767 回答