Very NOOB hurl question

Discuss about plugins that don't have a dedicated forum
Post Reply
NathanH
Posts: 107
Joined: Sun Jul 05, 2015 1:29 am
Location: Caldwell, Idaho

Very NOOB hurl question

Post 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
plouf
Posts: 472
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Very NOOB hurl question

Post 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()

Christos
User avatar
jPV
Posts: 604
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Very NOOB hurl question

Post 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.
NathanH
Posts: 107
Joined: Sun Jul 05, 2015 1:29 am
Location: Caldwell, Idaho

Re: Very NOOB hurl question

Post 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
Post Reply