how can I get the POST json?
majj opened this issue · 4 comments
When I POST the json payload:
`
import requests
payload = {'a':'v1','u':'v2'}
r = requests.post("http://127.0.0.1:8025/call", data=payload)
`
I got $input :
{"http_content_type":"application/x-www-form-urlencoded","http_user_agent":"python-requests/2.22.0","http_accept_encoding":"gzip, deflate","http_accept":"*/*","http_connection":"keep-alive","http_content_length":"9"}
How can I get the http_content?
Thanks.
It works when I modified the code:
`import json
import requests
data = {'a':'v1','u':'v2'}
headers = {'Content-type': 'application/json'}
payload = json.dumps(data)
r = requests.post("http://127.0.0.1:8025/callrpc", data=payload, headers=headers)`
Thanks!
but actually I got
{"http_user_agent":"python-requests/2.22.0","http_accept_encoding":"gzip, deflate","http_accept":"*/*","http_connection":"keep-alive","a":"v1","u":"v2","http_content_type":"application/json","http_content_length":"22"}
not a json string like the original {'a':'v1','u':'v2'}
by this way:
`data = {'data':{'a':'v1','u':'v2'}}
headers = {'Content-type': 'application/json'}
payload = json.dumps(data)
r = requests.post("http://127.0.0.1:8025/callrpc", data=payload, headers=headers)`
I can get the $input.data as the original {'a':'v1','u':'v2'}
I found this way:
`
bind {
data = <<JS
JSON.stringify({
"a": $input.a,
"u": $input.v
})
JS
}
`
It works, Thanks.