http Headers without content?

Everything else that doesn't fall into one of the other PB categories.
vwidmer
Enthusiast
Enthusiast
Posts: 286
Joined: Mon Jan 20, 2014 6:32 pm

http Headers without content?

Post by vwidmer »

How can I get the http headers without downloading the content?

Thanks
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: http Headers without content?

Post by idle »

On phone, you can use the header only flag with a get see doc
https://www.purebasic.com/documentation ... emory.html

edit: Glad I checked as I had a bug, I was returning 100 continue

Code: Select all

HttpRequest = HTTPRequestMemory(#PB_HTTP_Get, "https://atomicwebserver.com/index.html",0,0,#PB_HTTP_HeadersOnly)
If HttpRequest
  Debug "StatusCode: " + HTTPInfo(HTTPRequest, #PB_HTTP_StatusCode)
  Debug "headers: " + HTTPInfo(HTTPRequest,#PB_HTTP_Headers)
  FinishHTTP(HTTPRequest)
Else
  Debug "Request creation failed"
EndIf

User avatar
Piero
Addict
Addict
Posts: 865
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: http Headers without content?

Post by Piero »

vwidmer wrote: Mon Oct 21, 2024 1:35 am I just put stuff here and there and sometimes like magic it works.
You're talking about headers but I liked the signature :lol:
vwidmer
Enthusiast
Enthusiast
Posts: 286
Joined: Mon Jan 20, 2014 6:32 pm

Re: http Headers without content?

Post by vwidmer »

@idle: Thank you very much!! Not sure how I missed that but it is working as need.
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
vwidmer
Enthusiast
Enthusiast
Posts: 286
Joined: Mon Jan 20, 2014 6:32 pm

Re: http Headers without content?

Post by vwidmer »

Piero wrote: Mon Oct 21, 2024 2:50 pm
vwidmer wrote: Mon Oct 21, 2024 1:35 am I just put stuff here and there and sometimes like magic it works.
You're talking about headers but I liked the signature :lol:
Magic gets better with practice :lol:
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: http Headers without content?

Post by idle »

vwidmer wrote: Tue Oct 22, 2024 12:34 am @idle: Thank you very much!! Not sure how I missed that but it is working as need.
Thank you for not noticing as I was able to fix a bug in my code. :lol:
Post Reply