I'm trying to create a POST request with Tsung
<request>
<http url="api.whatever.com" method="POST" version="1.1" contents=""></http>
</request>
How can I send a JSON document in the contents attribute?
contents='{"name": "alex"}'
is of course invalid...
Is there a way I can send JSON with my POST request?
To post JSON to a REST API endpoint, you must send an HTTP POST request to the REST API server and provide JSON data in the body of the POST message. You also need to specify the data type in the body of the POST message using the Content-Type: application/json request header.
I was able to do this by replacing "
"
and adding the content type header application/json
So my example would become:
content_type='application/json' contents='{"name": "alex"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With