Get info code about connection to an URL

Discuss any general programming issues here
papiosaur
Posts: 217
Joined: Fri Mar 31, 2023 1:34 pm

Get info code about connection to an URL

Post by papiosaur »

Hello,

i would like to get an info code about the connection to an URL but i don't understand hurl plugin.

Example:

200 : ok
404 : not found

etc...

thanks for your help
plouf
Posts: 666
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Get info code about connection to an URL

Post by plouf »

yeah hURL is a mess .. took me long time to understand back then

here is an example who will receive 404

Code: Select all

@REQUIRE "hurl"

; this function will be called whenever there is new data
Function p_WriteData(data$)
	DebugPrint(data$)
EndFunction

; create easy object and configure it
e = hurl.Easy({URL = "https://www.google.com/NONEXISTING", WriteFunction = p_WriteData})
e:setopt_http_version(#CURL_HTTP_VERSION_1_1)
e:setopt_customrequest("GET")
e:perform()
; destroy easy object
responsecode = e:getinfo_response_code()
e:close()

DebugPrint("error code : "..responsecode)
End
Christos
papiosaur
Posts: 217
Joined: Fri Mar 31, 2023 1:34 pm

Re: Get info code about connection to an URL

Post by papiosaur »

It work perfect!!!

Not easy code but very interesting and usefull, i will investigate the hurl plugin.

Thanks a lot plouf!!!

Possibility to remove output window please?
plouf
Posts: 666
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Get info code about connection to an URL

Post by plouf »

Output window?
Christos
papiosaur
Posts: 217
Joined: Fri Mar 31, 2023 1:34 pm

Re: Get info code about connection to an URL

Post by papiosaur »

Yes, MorphOS open an output window with the content of the URL (file).
plouf
Posts: 666
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Get info code about connection to an URL

Post by plouf »

Its the
DebugPrint() command... Part of my example
Christos
papiosaur
Posts: 217
Joined: Fri Mar 31, 2023 1:34 pm

Re: Get info code about connection to an URL

Post by papiosaur »

No, i have removed the Debugprint...

e.perform() seems open the file of the url in an output window...
User avatar
jPV
Posts: 734
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Get info code about connection to an URL

Post by jPV »

papiosaur wrote: Thu Aug 29, 2024 6:00 pm e.perform() seems open the file of the url in an output window...
Did you remove the debug output from the write function too? In any case there's no output window by default.
papiosaur
Posts: 217
Joined: Fri Mar 31, 2023 1:34 pm

Re: Get info code about connection to an URL

Post by papiosaur »

@jPV: yes...

This is a code wich normally just show responsecode:

Code: Select all

@REQUIRE "hurl"

e = hurl.Easy({URL = "https://www.google.com"})
e:perform()
responsecode = e:getinfo_response_code()
e:close()
DebugPrint("error code : "..responsecode)
End
I have many caracters before the responsecode on MorphOS...
User avatar
jPV
Posts: 734
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Get info code about connection to an URL

Post by jPV »

If you don't provide a write function, it will output to stdout (shell). So it works as it should and if you don't want any output or store any data to anywhere, give it a function that does nothing.

This is a very minimal example:
e = hurl.Easy({URL = "https://www.google.com", WriteFunction = Function() EndFunction})

Here's what's told in the libcurl manual (googled it):
"libcurl offers its own default internal callback that takes care of the data if you do not set the callback with CURLOPT_WRITEFUNCTION. It simply outputs the received data to stdout."
Post Reply