27.07.2020, 20:27
(This post was last modified: 27.07.2020, 20:34 by benanderson_475.)
i tried it got the same error, looking at the documents it say "that you must send a unique identifier in the User-Agent header. Any requests with a prohibited or missing User-Agent will receive a 403 Forbidden error."
i don't know how to pass the headers with socket.url but i tried it with http.request, like the below with the User-Agent header, it returns the data
i don't know how to pass the headers with socket.url but i tried it with http.request, like the below with the User-Agent header, it returns the data
Code:
function get_request(url)
local http, ltn12, sink, res, err
ltn12 = require('ltn12')
http = require('socket.http')
sink = {}
res, err = http.request({
url = url,
method = 'GET',
headers =
{
["Accept"] = "*/*",
["User-Agent"] = "1234567897", -- i think this can be any number?
},
sink = ltn12.sink.table(sink)
})
if sink then
return table.concat(sink)
else
return nil, err
end
end
x = get_request('https://api.met.no/weatherapi/locationforecast/2.0/complete?lat=67.8596&lon=35.0904&altitude=13')
log(x)