The Headers post fine but the associated XML seems to be taken as string data only, XML is not processed. XML string is of the form:
params = '''<?xml version="1.0" encoding"="UTF-8 "?>
<MainRequest>
<requestEnvelope><errorLanguage>en_US</errorLanguage>
</requestEnvelope></MainRequest>'''
The POST is of the form:
enc_params = urllib.quote(params)
request = urllib2.Request("https://myURL/",enc_params, headers)
The send of the XML i开发者_运维问答s of the form:
%3C%3Fxml%20version%3D%221.0%22%20encoding%22%3D%22UTF-8%20%22%3F%3E%0A%3CMainReq
uest%3E%0A%3CrequestEnvelope%3E%3CerrorLanguage%3Een_US%3C/errorLanguage%3E%0A%3
C/requestEnvelope%3E
The error message then indicates XML content is missing.
Any ideas would be helpful.
Are you adding a content-type header? To tell the server your request is XML, add the following before sending the request:
request.add_header('Content-Type', 'text/xml')
Take out the "urllib.quote()" call. That's what created the string which starts "%3C%3Fxml". If you want to POST XML then just send that XML string as the data, along with the Content-Type that ataylor mentioned. (But in most cases that doesn't make a difference.)
精彩评论