![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Classic ASP) HTTP Redirect HandlingExamine HTTP redirects.
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <% ' This example assumes the Chilkat API to have been previously unlocked. ' See Global Unlock Sample for sample code. ' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.Http") set http = Server.CreateObject("Chilkat.Http") ' Please note: The URL used in this example was a valid redirect many years ago, ' but the site does not exist any longer.. url = "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 automatically taken: http.FollowRedirects = 1 ' Send the HTTP GET and return the content in a string. html = http.QuickGetStr(url) If (http.LastMethodSuccess <> 1) Then Response.Write "<pre>" & Server.HTMLEncode( http.LastErrorText) & "</pre>" End If ' On success, LastErrorText will provide information about ' what happened during the call. Response.Write "<pre>" & Server.HTMLEncode( "--------------- LastErrorText ------------------") & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( http.LastErrorText) & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( "------------------------------------------------") & "</pre>" ' In this case, we see something like this: ' ChilkatLog: ' QuickGetHtml: ' DllDate: Jul 27 2007 ' url: http://www.planyourweddingonline.co.za/ ' httpServer: www.planyourweddingonline.co.za ' port: 80 ' StatusCode: 302 ' StatusText: Found ' Reading chunked response ' redirectUrl: main/main/home/index.php ' url: http://www.planyourweddingonline.co.za/main/main/home/index.php ' StatusCode: 302 ' StatusText: Found ' Reading chunked response ' redirectUrl: /main/main/home/index.php?SMC=1 ' url: http://www.planyourweddingonline.co.za/main/main/home/index.php?SMC=1 ' StatusCode: 200 ' StatusText: OK ' CompressedSize: 7434 ' UncompressedSize: 40999 ' Was the GET redirected? If (http.WasRedirected = 1) Then Response.Write "<pre>" & Server.HTMLEncode( "Chilkat HTTP followed the redirect.") & "</pre>" ' Display the final redirect URL: Response.Write "<pre>" & Server.HTMLEncode( "Final URL:") & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( http.FinalRedirectUrl) & "</pre>" ' Note the HTML returned is from the final redirect URL. Else Response.Write "<pre>" & Server.HTMLEncode( "Not redirected.") & "</pre>" End If status = http.LastStatus If (status = 200) Then Response.Write "<pre>" & Server.HTMLEncode( "status = 200, OK!") & "</pre>" Else Response.Write "<pre>" & Server.HTMLEncode( "HTTP Response status = " & status) & "</pre>" ' Display the complete response header. Response.Write "<pre>" & Server.HTMLEncode( http.LastResponseHeader) & "</pre>" End If ' Now try it without following redirects: Response.Write "<pre>" & Server.HTMLEncode( "-------- Now trying without following redirects....") & "</pre>" http.FollowRedirects = 0 ' Send the HTTP GET and return the content in a string. html = http.QuickGetStr(url) If (http.LastMethodSuccess <> 1) Then ' the HTML string can NULL if a 302 redirect response is received. Response.Write "<pre>" & Server.HTMLEncode( "HTML string returned NULL...") & "</pre>" End If ' On success, LastErrorText will provide information about ' what happened during the call. Response.Write "<pre>" & Server.HTMLEncode( "--------------- LastErrorText ------------------") & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( http.LastErrorText) & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( "------------------------------------------------") & "</pre>" ' In this case, we see something like this: ' ChilkatLog: ' QuickGetHtml: ' DllDate: Jul 27 2007 ' url: http://www.planyourweddingonline.co.za/ ' StatusCode: 302 ' StatusText: Found ' Reading chunked response ' redirectUrl: main/main/home/index.php ' Was this a redirect? Even if FollowRedirects is false, ' WasRedirected will be true (non-zero) if the response ' indicated a redirect. If (http.WasRedirected = 1) Then Response.Write "<pre>" & Server.HTMLEncode( "This was a redirect response") & "</pre>" ' When redirects are not followed, FinalRedirectUrl ' contains the redirect URL that would've been taken... ' Display the redirect URL, which was not taken... Response.Write "<pre>" & Server.HTMLEncode( "Redirect URL:") & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( http.FinalRedirectUrl) & "</pre>" Else Response.Write "<pre>" & Server.HTMLEncode( "Not redirected.") & "</pre>" End If status = http.LastStatus If (status = 200) Then Response.Write "<pre>" & Server.HTMLEncode( "status = 200, OK!") & "</pre>" Else Response.Write "<pre>" & Server.HTMLEncode( "HTTP Response status = " & status) & "</pre>" ' Display the complete response header. Response.Write "<pre>" & Server.HTMLEncode( http.LastResponseHeader) & "</pre>" End If %> </body> </html> |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.