pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

HTTP

案例程序

GET method

from m5stack import *
from m5ui import *
from uiflow import *
import urequests
setScreenColor(0x222222)

try:
  req = urequests.request(method='GET', url='https://httpbin.org/get', headers={'Accept':'application/json'})
  print((str('Status: ') + str((req.status_code))))
  print(req.text)
  gc.collect()
  req.close()
except:
  print((str('Status: ') + str((req.status_code))))
  print('Fail')

POST method

from m5stack import *
from m5ui import *
from uiflow import *
import urequests
from libs.json_py import *
setScreenColor(0x222222)

try:
  req = urequests.request(method='POST', url='https://httpbin.org/post',json={'Payload':(py_2_json({'msg':'hello'}))}, headers={'Content-Type':'application/json'})
  print((str('Status: ') + str((req.status_code))))
  print(req.text)
  gc.collect()
  req.close()
except:
  print((str('Status: ') + str((req.status_code))))
  print('Fail')

功能说明

try:
  req = urequests.request(method='GET', url='https://httpbin.org/get', headers={'Accept':'application/json'})
  print((str('Status: ') + str((req.status_code))))
  print(req.text)
  gc.collect()
  req.close()
except:
  print((str('Status: ') + str((req.status_code))))
  print('Fail')
  • 创建HTTP请求,方法支持GET、POST、DELET、PUT、PATCH。
print(req.status_code)
  • 返回状态码
print(req.text)
  • 获取返回的请求数据
On This Page