Hi, here’s a website called postman echo: Postman
If you do something like:
response = urequests.get("http://postman-echo.com/get?foo1=bar1&foo2=bar2")
print(response.json())
Then you’ll get the result of:
{'headers': {'x-amzn-trace-id': 'Root=1-646c391b-2135fc7f018223172155456c', 'x-forwarded-proto': 'http', 'x-forwarded-port': '80', 'host': 'postman-echo.com'}, 'args': {'foo1': 'bar1', 'foo2': 'bar2'}, 'url': 'http://postman-echo.com/get?foo1=bar1&foo2=bar2'}
Which is similar to what the website says it will return:
{
"args": {
"foo1": "bar1",
"foo2": "bar2"
},
"headers": {
"x-forwarded-proto": "https",
"host": "postman-echo.com",
"accept": "*/*",
"accept-encoding": "gzip, deflate",
"cache-control": "no-cache",
"postman-token": "5c27cd7d-6b16-4e5a-a0ef-191c9a3a275f",
"user-agent": "PostmanRuntime/7.6.1",
"x-forwarded-port": "443"
},
"url": "https://postman-echo.com/get?foo1=bar1&foo2=bar2"
}
As for why this doesn’t work:
#POST
data = {
'name': 'John',
'age': 30
}
response = urequests.post('192.168.1.1:8080', json=data)
print(response.text)
It’s hard to tell. I don’t know what server you are talking to and what you expect it to return.
For example, if I do:
response = urequests.post("http://postman-echo.com/post")
print(response.json())
I get back:
{'files': {}, 'headers': {'x-forwarded-port': '80', 'content-type': 'application/json', 'x-amzn-trace-id': 'Root=1-646c3a52-32c90cfc34128f4b140d5218', 'host': 'postman-echo.com', 'x-forwarded-proto': 'http'}, 'args': {}, 'form': {}, 'data': {}, 'json': None, 'url': 'http://postman-echo.com/post'}
Try playing around with the postman echo service to get the hang of who POST/GET etc. work.