How can I handle a redirect in HTTP? |
|
Date Entered: 01/11/2000
|
Last Update: 04/23/2008
|
APPLIES TO |
|
|
|
|
SYNOPSIS |
How can I handle a redirect in HTTP? |
SOLUTION |
Version 5 of IP*Works! includes a FollowRedirects property that you can use to automatically handle redirections. For example:
HTTP1.FollowRedirects = frAlways
HTTP1.Get "http://www.nsoftware.com"
In previous versions of IP*Works:
The server gives the new location in the
Location header and then returns an error number
301 or 302. The http control will generate an
error/exception with the text "Redirected." You
should save the Location header in the Header
event, handle the error/exception
generated/raised by the control and request this
new location.
An example in VB is shown below:
Dim gNewURL as String
Private Sub HTTP1_Header(Field As String, Value As String)
If LCase(Field) = "location" Then gNewURL = Value
End Sub
Private Sub Command1_Click()
On Error GoTo errhandler
HTTP1.WinsockLoaded = True
HTTP1.URL = "http://www.microsoft.com/support"
HTTP1.Action = a_GetDocument
Exit Sub
errhandler:
If Err.Number = 20152 And (Left(Error, 4) = "303 " Or _
Left(Error, 4) = "302 ") Then
HTTP1.URL = gNewURL 'assign new URL
Resume 'repeat action
End If
End Sub |