adafruit / Adafruit_CircuitPython_Requests

Requests-like interface for web interfacing
MIT License
51 stars 37 forks source link

Add Cellular Examples #27

Closed brentru closed 4 years ago

brentru commented 4 years ago

Adding examples for using this library with a cellular (adafruit/Adafruit_CircuitPython_FONA#3) interface.

Tested with Adafruit CircuitPython 5.0.0 on 2020-03-02; Adafruit Metro M4 Express with samd51j19

code.py output:
Attaching to network...
Attaching to network...
..
Connecting to network...
Connecting to network...
Fetching text from http://wifitest.adafruit.com/testwifi/index.html
b'HTTP/1.1 200 OK'
----------------------------------------
Text Response:  This is a test of Adafruit WiFi!
If you can read this, its working :)

----------------------------------------
Fetching JSON data from http://httpbin.org/get
b'HTTP/1.1 200 OK'
----------------------------------------
JSON Response:  {'url': 'http://httpbin.org/get', 'headers': {'User-Agent': 'Adafruit CircuitPython', 'Host': 'httpbin.org', 'X-Amzn-Trace-Id': 'Root=1-5eb1c2c8-eaed6e4c24be7bd6171daee6'}, 'args': {}, 'origin': '172.58.206.207'}
----------------------------------------
POSTing data to http://httpbin.org/post: 31F
b'HTTP/1.1 200 OK'
----------------------------------------
Data received from server: 31F
----------------------------------------
POSTing data to http://httpbin.org/post: {'Date': 'July 25, 2019'}
b'HTTP/1.1 200 OK'
----------------------------------------
JSON Data received from server: {'Date': 'July 25, 2019'}
----------------------------------------

code.py output:
Attaching to network...
...
Connecting to network...
Fetching JSON data from http://httpbin.org/get...
b'HTTP/1.1 200 OK'
------------------------------------------------------------
Response's Custom User-Agent Header: Adafruit CircuitPython,blinka/1.0.0
------------------------------------------------------------
Response HTTP Status Code:  200
------------------------------------------------------------
Raw Response:  b'{\n  "args": {}, \n  "headers": {\n    "Host": "httpbin.org", \n    "User-Agent": "Adafruit CircuitPython,blinka/1.0.0", \n    "X-Amzn-Trace-Id": "Root=1-5eb1c36e-340d6329dbaef4b9710b684f"\n  }, \n  "origin": "172.58.235.170", \n  "url": "http://httpbin.org/get"\n}\n'```