1

I have a curl request as below:

curl -X POST \
https://example.com \
-H 'Content-Type: multipart/form-data' \
--form-string 'message=<messageML>Hello world!</messageML>'

How do i pass --form-string data in python request?

Thanks!

1 Answer 1

1

Use the files parameter to post your data, example:

import requests

url = 'https://httpbin.org/anything'
data = {'message':'<messageML>Hello world!</messageML>'}
r = requests.post(url, files=data)

print(r.text)

You don't have to use headers because 'multipart/form-data' is the default 'Content-Type' header when posting files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.