Page 1 of 2

Get info code about connection to an URL

Posted: Thu Aug 29, 2024 2:00 pm
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

Re: Get info code about connection to an URL

Posted: Thu Aug 29, 2024 4:19 pm
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

Re: Get info code about connection to an URL

Posted: Thu Aug 29, 2024 5:28 pm
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?

Re: Get info code about connection to an URL

Posted: Thu Aug 29, 2024 5:49 pm
by plouf
Output window?

Re: Get info code about connection to an URL

Posted: Thu Aug 29, 2024 5:53 pm
by papiosaur
Yes, MorphOS open an output window with the content of the URL (file).

Re: Get info code about connection to an URL

Posted: Thu Aug 29, 2024 5:57 pm
by plouf
Its the
DebugPrint() command... Part of my example

Re: Get info code about connection to an URL

Posted: Thu Aug 29, 2024 6:00 pm
by papiosaur
No, i have removed the Debugprint...

e.perform() seems open the file of the url in an output window...

Re: Get info code about connection to an URL

Posted: Fri Aug 30, 2024 8:16 am
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.

Re: Get info code about connection to an URL

Posted: Sun Sep 01, 2024 6:37 pm
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...

Re: Get info code about connection to an URL

Posted: Sun Sep 01, 2024 7:42 pm
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."