【问题标题】:How to set up SOAPMessage boundary?如何设置 SOAPMessage 边界?
【发布时间】:2021-04-06 01:30:39
【问题描述】:

我在 java 中发送一个 SoapMessage。我一直在设置正确的标头时遇到问题,正是 Content-Type 的一部分,应该如下所示:

Content-Type: multipart/related; type="application/xop+xml"; start="<rootpart@soapui.org>"; start-info="text/xml"; boundary="the boundary of my soapmessage"

我不知道如何将边界参数添加到我的标题中,以便它与肥皂消息的其余部分相匹配。 我的肥皂信息如下所示:

------=_Part_0_5841104.1608651610791
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: 8bit
Content-ID: <rootpart@soapui.org>

MYXML

------=_Part_0_5841104.1608651610791

Content-Type: application/zip; name=Worker.zip
Content-Transfer-Encoding: binary
Content-ID: <MYFILE.zip>
Content-Disposition: attachment; name="MYFILE.zip"; filename="MYFILEr.zip"

MYATTACHMENT

soapbody 中的边界部分是自动生成的(------=_Part_0_5841104.1608651610791),每次我发送消息时它都会改变。当我尝试添加标题时,我会这样做:

MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
        SOAPMessage soapMessage = messageFactory.createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();

    String authString = "login" + ":" + "password";
    String enc = java.util.Base64.getEncoder().encodeToString((authString).getBytes(StandardCharsets.UTF_8));
    MimeHeaders hd = soapMessage.getMimeHeaders();
    hd.addHeader("POST","where");
    hd.addHeader("Accept-Encoding","gzip,deflate");
    hd.addHeader("Content-Type","multipart/related; type=\"application/xop+xml\"; start=\"<rootpart@soapui.org>\"; start-info=\"text/xml\"; boundary=\"----=_????????\"");
    hd.addHeader("SOAPAction","Action");
    hd.addHeader("MIME-Version","1.0");
    hd.addHeader("Host","MyHost");
    hd.addHeader("Connection","Keep-Alive");
    hd.addHeader("User-Agent","Apache-HttpClient/4.1.1 (java 1.5)");
    hd.addHeader("Authorization", "Basic " + enc);

如何将这个适当的边界添加到我的标题中?

【问题讨论】:

    标签: java soap mime boundary


    【解决方案1】:

    我今天一直在努力解决这个问题,这是我找到的第一个成功。

    当您完成创建 SOAPMessage 后,在其上调用 saveCanges()。这将使用正确的内容类型填充 mimeheader,其中包含边界。

    SOAPMessage msg = //create message...
    msg.saveChanges();
    msg.getMimeHeaders(); //Now contains a content-type with boundary that you can send as request properties.
    

    希望这对遇到此问题的人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-09
      • 2013-05-08
      • 1970-01-01
      • 2020-07-12
      • 2013-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多