如何使用Python在Mtom / xop请求中发送Content-id

时间:2019-09-03 06:29:56

标签: python xml mtom xop

我正在尝试使用python行为发送mtom / xop请求。我不明白如何发送Content-id

我正在使用python3和xml有效负载。

Python代码

url = 'http://www.example.com'

headers = {
    'Content-Type': 'multipart/related; boundary="MIMEBoundary_337cc20b65587a0a19b6cc64978c33d1f46c4058e18a82ed"; '
                    'type="application/xop+xml";  '
                    'start="<0.237cc20b65587a0a19b6cc64978c33d1f46c4058e18a82ed@apache.org>"; '
                    'start-info="application/soap+xml"; action="urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-b"',
    'Content-ID': '<0.237cc20b65587a0a19b6cc64978c33d1f46c4058e18a82ed@apache.org>'
}

错误

errors reported by MtomMessageValidator
Part has no Content-ID header
Exception HttpParseException
    gov.nist.toolkit.http.HttpParseException: Part has no Content-ID header
    at gov.nist.toolkit.http.PartParserBa.initPart(PartParserBa.java:30)
    at gov.nist.toolkit.http.PartParserBa.&lt;init>(PartPar`erBa.java:19)

--MIMEBoundary112233445566778899--

使用此代码在有效负载文件中发送标头并发送POST请求

tree = ET.parse(os.path.dirname(file) + '/../Payloads/XSD/ITI-41/ITI-41-S1_1.xml') 
root = tree.getroot()
xmlstr = ET.tostring(root, encoding='utf8', method='xml') 
body = xmlstr.decode('utf8')
# xml.dom.minidom.parseString(body) 
response = requests.post(url, data=body, headers=headers) 
context.status_code = response.status_code 
context.response_document = response.text

0 个答案:

没有答案