如何设置soapmessage边界?

pdkcd3nj  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(253)

我正在用java发送soapmessage。我一直在设置正确的标题时遇到问题,正是内容类型的一部分,应该如下所示:

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

我不知道如何将boundary参数添加到我的头中,以便它与soap消息的其余部分匹配。我的soap消息如下所示:

------=_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中的边界部分是自动生成的(----=\u part\u 0\u 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);

如何将此适当的边界添加到标题中?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题