alash3al/sqler

how can I get the POST json?

majj opened this issue · 4 comments

majj commented

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.

majj commented

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!

majj commented

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'}

majj commented

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'}

majj commented

I found this way:

`
bind {
data = <<JS
JSON.stringify({
"a": $input.a,
"u": $input.v
})
JS
}

`

It works, Thanks.