Hello,
today i tried to program a get request via my esp8266.
I used the basic configuration of https://docs.micropython.org/ .
My aim is to send 2 values to a php-site on my rasppberry. I've got the fields name and age.
Before i came to micropython i played a lil bit with lua.
This command works so far:
...
conn:send("GET /get.php?name=444&age=555"
...
my structure in micropython look like this:
url = '192.168.1.12'
addr = socket.getaddrinfo(url, 80)[0][-1]
s = socket.socket()
s.connect(addr)
s.send('GET /get.php name=444&age=555')
Sadly my webserver can not understand the pythonpart. Do you guys know what i have made wrong? How the send command has to look like correctly? Thanks so far
HTTP GET request micropython
Re: HTTP GET request micropython
We have an example of a simple HTTP client: https://github.com/micropython/micropyt ... _client.py . By looking at it you should be able to tell what's wrong in your example (your HTTP request string is not conforming to HTTP standard).
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Re: HTTP GET request micropython
You might also want to consider trying out urequests (https://github.com/micropython/micropyt ... equests.py) instead of writing it yourself.
Once you get urequests.py on your filesystem so it can be imported it would simplify your code to the following (minus any typos I might've made):
Once you get urequests.py on your filesystem so it can be imported it would simplify your code to the following (minus any typos I might've made):
Code: Select all
import urequests
response = urequests.get("http://192.168.1.12/get.php?name=444&age=555")
response.close()
Re: HTTP GET request micropython
Thank You very much! That's working!
But im still interested in the correct code of my example.
I tried s.send(b'GET /get.php HTTP/1.0\r\n\r\nname=1234&age=5678') and failed.

But im still interested in the correct code of my example.
I tried s.send(b'GET /get.php HTTP/1.0\r\n\r\nname=1234&age=5678') and failed.
Re: HTTP GET request micropython
The first line of an HTTP request is the method (GET, POST, etc.) following by the path (including the query string) and finally the HTTP version. Altogether for your case that would be something like:
Your most recent example placed the parameters in the body portion of the request (the body starts after two consecutive \r\n newlines). This doesn't make sense for a GET.
Code: Select all
s.send(b'GET /get.php?name=1234&age=5678 HTTP/1.0\r\n\r\n')