Results 1 to 6 of 6

Thread: Easiest way to get http header response from URL?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    58

    Easiest way to get http header response from URL?

    Is there a simple way to feed in a URL and just get the response? 301, 200, 404 etc?

    I have seen the ICMP stuff but I would like to make it as small and simple as possible. something along the lines of wget.
    -------------------------------
    StupidMonkee

  2. #2
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Easiest way to get http header response from URL?

    Is this good for you? (win2k+)
    Code:
    Option Explicit
    'Requires a reference to Microsoft WinHTTP Services
    Private Sub Form_Load()
    Dim WebLink As WinHttp.WinHttpRequest 
    
      Set WebLink = New WinHttp.WinHttpRequest
      
      WebLink.Open "GET", "http://www.martind1.com/"
      WebLink.Send
      
      Debug.Print WebLink.GetAllResponseHeaders
      'or
      Debug.Print WebLink.GetResponseHeader("Content-Type")
    
      Set WebLink = Nothing
    End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    58

    Re: Easiest way to get http header response from URL?

    Yes this looks real good. It will at least allow me to know that the pages are live (200) status.

    however I can't seem to determine if there was a redirect in there (301 code)
    use for example http://www.cnet.com/news
    it should redirect to http://news.redir.com.com/news

    but i only get the last result (the 200).
    -------------------------------
    StupidMonkee

  4. #4
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Easiest way to get http header response from URL?

    This is not something I'm too familiar with. Maybe someone else knows more and theres always MSDN.

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    58

    Re: Easiest way to get http header response from URL?

    Thanks though. Yours is definitely a good start and very usefull for me.

    I have a feeling that i might be able to use the ResponseStream to capture it but I am not quite sure how.

    So anyone out there ... I am still listening.

    They key solution I now need is something that captures 301 redirects before hitting a 200 success page.
    -------------------------------
    StupidMonkee

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    58

    Re: Easiest way to get http header response from URL?

    Found it!

    I just had to turn off the enable redirects and ... success!

    Code:
      Dim WebLink As WinHttp.WinHttpRequest
    
      Set WebLink = New WinHttp.WinHttpRequest
      
      WebLink.Option(WinHttpRequestOption_EnableRedirects) = False
    
      WebLink.Open "GET", "http://www.cnet.com/news"
      WebLink.Send
      
      MsgBox WebLink.Status
    -------------------------------
    StupidMonkee

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width