Curl has an option to send a file as is with the --data-binary option.
When testing the Qualys WAS API, the following curl command works:
curl -u "username:password" -H "content-type: text/xml" -X "POST" --data-binary @- "https://qualysapi.qualys.com/qps/rest/3.0/search/was/webapp" < post.xml post.xml:
<ServiceRequest><filters><Criteria operator="CONTAINS" field="name">PB - </Criteria></filters></ServiceRequest> Using Python's requests module, I keep receiving a HTTPError: 415 Client Error: Unsupported Media Type.
import requests url = 'https://qualysapi.qualys.com/qps/rest/3.0/search/was/webapp' payload = '<ServiceRequest><filters><Criteria operator="CONTAINS" field="name">PB - </Criteria></filters></ServiceRequest>' headers = {'X-Requested-With': 'Python requests', 'Content-type': 'application/json'} r = requests.post(url, data=payload, headers=headers, auth=('username', 'password')) When trying to submit file files parameter, it also ended in a 415 error.
import requests url = 'https://qualysapi.qualys.com/qps/rest/3.0/search/was/webapp' payload = '<ServiceRequest><filters><Criteria operator="CONTAINS" field="name">PB - </Criteria></filters></ServiceRequest>' headers = {'X-Requested-With': 'Python requests', 'Content-type': 'application/json'} r = requests.post(url, data=payload, headers=headers, auth=('username', 'password')) The reason I'm setting this up is to incorporate this into the qualysapi Python package.
--data-binarywithrequests. The dupe I linked to does ask that question.payloadcontents and yourContent-typeheader, my immediate response to your posted answer below is Yeah, duh. :-D