Hello,
I am able to perform some http requests and get back data from web sites with simple host names. But I can’t seem to get it to work with more complicated hostnames. Is this because it doesn’t like the “/” and or “?” inside the hostname? Thank you
For example, using these addresses in the s.send line:
api.geoiplookup.net - works
api.geoiplookup.net/?query=xxx.xxx.xxx.xxx does not work
freegeoip.live/json does not work
freegeoip.live/xml does not work
Is there a way I can format the hostname to work within micropython?
This code works, and gives back country and lat/lon info for my Portenta using wifi
addr = socket.getaddrinfo('api.geoiplookup.net', 80)[0][-1]
s = socket.socket()
s.connect(addr)
s.send(b'GET / HTTP/1.1\r\nHost: api.geoiplookup.net\r\n\r\n')
data = s.recv(1000)
print (data)
Below does not work and gets an error “400 bad request”
addr = socket.getaddrinfo('freegeoip.live', 80)[0][-1]
s = socket.socket()
s.connect(addr)
s.send(b'GET / HTTP/1.1\r\nHost: freegeoip.live/json/\r\n\r\n')
data = s.recv(1000)
print (data)