Page 1 of 1
Very NOOB hurl question
Posted: Tue Apr 25, 2023 11:22 pm
by NathanH
Hi,
I'm sorry but the hurl stuff is way over my head. The following curl command on linux gives me the data that I need:
curl >weather.txt -X GET "
https://api.weather.gov/stations/KBOI/o ... re_qc=true"
How do I do the same thing using hurl? Thanks much!
NathanH
Re: Very NOOB hurl question
Posted: Wed Apr 26, 2023 7:58 pm
by plouf
hURL is complicated to me too (:-))
but here seems that its a server idiom, that it does not return data without User-Agent header !! (that needed reverse chenking
Code: Select all
@REQUIRE "hurl"
Function p_WriteData(dataloc$)
DebugPrint(dataloc$)
EndFunction
url$ = "https://api.weather.gov/stations/KBOI/observations/latest?require_qc=true"
e = hurl.Easy({URL = url$, WriteFunction = p_WriteData})
e:setopt_http_version(#CURL_HTTP_VERSION_1_1)
e:setopt_httpheader({"User-Agent: NathanH Hollywood Script"})
e:perform()
Re: Very NOOB hurl question
Posted: Thu Apr 27, 2023 12:06 pm
by jPV
You can use the
high-level interface for easier access when you're just doing simple downloads.
To download as a file:
Code: Select all
DownloadFile("https://api.weather.gov/stations/KBOI/observations/latest?require_qc=true", {File = "weather.txt", Adapter = "hurl", UserAgent="YetAnotherWeatherApp/1.0"})
Or in a string variable for processing in Hollywood:
Code: Select all
Local data$ = DownloadFile("https://api.weather.gov/stations/KBOI/observations/latest?require_qc=true", {Adapter = "hurl", UserAgent="YetAnotherWeatherApp/1.0"})
And yes, for some reason the default Hollywood user agent doesn't work for this server.
Re: Very NOOB hurl question
Posted: Mon May 01, 2023 12:28 am
by NathanH
Thanks guys,
These all work just great! It seems the UserAgent option was the catch. I don't know enough to know that that could have been the problem. Thanks.
NathanH