+ Reply to Thread
Results 1 to 6 of 6

Using VBA to find HTTP redirects

Hybrid View

  1. #1
    Registered User
    Join Date
    01-19-2009
    Location
    UK
    MS-Off Ver
    2007
    Posts
    60

    Using VBA to find HTTP redirects

    Hi,

    I'm trying to find a way to get VBA to do the following:
    1. Follow a URL
    2. Check if it's being 301 redirected
    3. Get the URL it's redirecting to
    4. Check that the redirect is not a 404

    I made a way to use Internet Explorer to do this, but it means IE has to load and finish rendering the entire page each time. (This is faster than I can do it manually, and obviously means I don't need to be there, but it's kinda slow)

    Any ideas?

    Thanks,
    .
    - AKK9 -

  2. #2
    Registered User
    Join Date
    01-19-2009
    Location
    UK
    MS-Off Ver
    2007
    Posts
    60

    Re: Using VBA to find HTTP redirects

    Any ideas? Maybe someone can point me in the right direction?

  3. #3
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Using VBA to find HTTP redirects

    You can do this with the WinHttpRequest object - see http://stackoverflow.com/questions/2...xmlhttp-object.
    Post responsibly. Search for excelforum.com

  4. #4
    Registered User
    Join Date
    01-19-2009
    Location
    UK
    MS-Off Ver
    2007
    Posts
    60

    Re: Using VBA to find HTTP redirects

    Got it working. Thanks.

  5. #5
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Using VBA to find HTTP redirects

    Why not post your code for the benefit of others?

  6. #6
    Registered User
    Join Date
    01-19-2009
    Location
    UK
    MS-Off Ver
    2007
    Posts
    60

    Re: Using VBA to find HTTP redirects

    Well, I haven't actually got anything working yet but had a quick read through the WinHTTP reference and it seems simple enough. You can send a HTTP request, get the status code, then get the Location from the response header. Everything I need without having to load any web pages in IE.

    I don't know if the status code will actually return 301 if the redirect is working, because I think it might follow the redirect and then return 200, but the if the Location in the header is different to the URL you use in the request, then I think it's safe to assume you are being redirected.

    That said, I haven't even typed a single letter of code yet so I'll try to report back when I get round to making this.

    Thanks,

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1