Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Tracing HTTP RedirectsExample to trace through HTTP redirects. LOCAL loHttp LOCAL lnSuccess LOCAL lcUrl LOCAL lcHtml LOCAL lnStatus LOCAL lnLoopCount loHttp = CreateObject('Chilkat.Http') * Any string unlocks the component for the 1st 30-days. lnSuccess = loHttp.UnlockComponent("Anything for 30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loHttp.LastErrorText) QUIT ENDIF lcUrl = "http://www.planyourweddingonline.co.za/" * The FollowRedirects property controls whether redirects * are automatically followed. The default behavior is to * automatically follow redirects. * Explicitly set FollowRedirects so that redirects are NOT automatically taken: loHttp.FollowRedirects = 0 * Send the HTTP GET and return the content in a string. lcHtml = loHttp.QuickGetStr(lcUrl) IF (lcHtml = NULL ) THEN =MESSAGEBOX(loHttp.LastErrorText) ENDIF lnStatus = loHttp.LastStatus ? "HTTP Response Status: " + STR(lnStatus) * The FinalRedirectUrl property will contain the redirect URL * If FollowRedirects was equal to 1, then all of the * intermediate redirects (if any) would be followed until * there were no more redirects. However, because * FollowRedirects is not 1, FinalRedirectUrl contains * the next redirect URL. ? "Redirect URL: " + loHttp.FinalRedirectUrl lnLoopCount = 0 DO WHILE (lnStatus = 302) lcUrl = loHttp.FinalRedirectUrl lcHtml = loHttp.QuickGetStr(lcUrl) IF (lcHtml = NULL ) THEN =MESSAGEBOX(loHttp.LastErrorText) EXIT ENDIF lnStatus = loHttp.LastStatus ? "Redirect URL: " + loHttp.FinalRedirectUrl * You may wish to check that if FinalRedirectUrl * equals the URL just retrieved. If so, then break out of the * loop. (This check is omitted in this example.) * Instead, this example will prevent infinite loops by * keeping a loopCount and only allows following a max * of 10 redirects: lnLoopCount = lnLoopCount + 1 IF (lnLoopCount > 10) THEN EXIT ENDIF ENDDO |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser