![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java 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
(PowerBuilder) Http Follow RedirectsSee more HTTP ExamplesDemonstrates how to automatically follow redirects.
integer li_rc oleobject loo_Http string ls_Url string ls_JsonResponse loo_Http = create oleobject li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") if li_rc < 0 then destroy loo_Http MessageBox("Error","Connecting to COM object failed") return end if // If you would like to see the HTTP session log to see how // HTTP redirects were followed. loo_Http.SessionLogFilename = "c:/temp/qa_output/sessionLog.txt" // Run the test using this URL. // (Works while httpbin.org keeps the test endpoint available.) ls_Url = "https://httpbin.org/redirect-to?url={$redirectUrl}&status_code={$statusCode}" loo_Http.SetUrlVar("redirectUrl","https://chilkatsoft.com/helloWorld.json") loo_Http.SetUrlVar("statusCode","302") ls_JsonResponse = loo_Http.QuickGetStr(ls_Url) if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Http return end if Write-Debug "Response status code: " + string(loo_Http.LastStatus) Write-Debug ls_JsonResponse // How to tell if the request was redirected, and if so, // what was the final redirect URL? Write-Debug "Was Redirected: " + string(loo_Http.WasRedirected) Write-Debug "Final Redirect URL: " + loo_Http.FinalRedirectUrl // Output: // Response status code: 200 // { "hello": "world" } // Was Redirected: True // Final Redirect URL: https://chilkatsoft.com/helloWorld.json // ----------------------------------------------- // Here are the contents of the sessionLog.txt // ---- Sending Sat, 30 Aug 2025 11:41:37 GMT ---- // GET /redirect-to?url=https%3A%2F%2Fchilkatsoft.com%2FhelloWorld.json&status_code=302 HTTP/1.1 // Host: httpbin.org // Accept: */* // Accept-Encoding: gzip // // // ---- Received Sat, 30 Aug 2025 11:41:37 GMT ---- // HTTP/1.1 302 FOUND // Date: Sat, 30 Aug 2025 11:41:38 GMT // Content-Type: text/html; charset=utf-8 // Content-Length: 0 // Connection: keep-alive // Server: gunicorn/19.9.0 // Location: https://chilkatsoft.com/helloWorld.json // Access-Control-Allow-Origin: * // Access-Control-Allow-Credentials: true // // // ---- Sending Sat, 30 Aug 2025 11:41:38 GMT ---- // GET /helloWorld.json HTTP/1.1 // Host: chilkatsoft.com // Accept: */* // Accept-Encoding: gzip // // // ---- Received Sat, 30 Aug 2025 11:41:38 GMT ---- // HTTP/1.1 200 OK // Content-Type: application/json // Last-Modified: Sun, 20 Aug 2023 11:36:27 GMT // Accept-Ranges: bytes // ETag: "34c27f8e5ad3d91:0" // Server: Microsoft-IIS/10.0 // X-Powered-By: ASP.NET // Date: Sat, 30 Aug 2025 11:41:38 GMT // Content-Length: 22 // // { "hello": "world" } destroy loo_Http |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.