HTTP

Use the API in the HTTP module to send HTTP requests to the server to obtain data.

import urequests

//GET request
req = urequests.request(
    method='GET',
    url='http://api.m5stack.com/v1',
    headers={'Content-Type':'text/html'}
    )

//POST request
req = urequests.request(
    method='POST',
    url='http://api.m5stack.com/v1',
    json={'KEY':'VALUE'},
    headers={'Content-Type':'text/html'}
    )

//Get the response body status code
print(req.status_code)

//Get the response body Reason-Phrase
print(req.reason)

//Get the native response body
print(req.content)

//Get response body string
print(req.text)

//Get response body JSON
print(req.json)
On This Page