ASP Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++DelphiFoxProJavaPerlPythonRubySQL ServerVBScript

ASP Examples

ASP String
ASP Byte Array
Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
S/MIME
Socket
Spider
RSA Encryption
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

HTTP Redirect Handling

Examine HTTP redirects.

Download Chilkat HTTP ActiveX

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
set http = Server.CreateObject("Chilkat.Http")

'  Any string unlocks the component for the 1st 30-days.
success = http.UnlockComponent("Anything for 30-day trial")
If (success <> 1) Then
    Response.Write Server.HtmlEncode(http.LastErrorText) & "<br>"

End If

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 (html = vbNullString ) Then
    Response.Write Server.HtmlEncode(http.LastErrorText) & "<br>"
End If

'  On success, LastErrorText will provide information about
'  what happened during the call.
Response.Write Server.HtmlEncode("--------------- LastErrorText ------------------") & "<br>"
Response.Write Server.HtmlEncode(http.LastErrorText) & "<br>"
Response.Write Server.HtmlEncode("------------------------------------------------") & "<br>"

'  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 Server.HtmlEncode("Chilkat HTTP followed the redirect.") & "<br>"

    '  Display the final redirect URL:
    Response.Write Server.HtmlEncode("Final URL:") & "<br>"
    Response.Write Server.HtmlEncode(http.FinalRedirectUrl) & "<br>"

    '  Note the HTML returned is from the final redirect URL.

Else
    Response.Write Server.HtmlEncode("Not redirected.") & "<br>"
End If

status = http.LastStatus
If (status = 200) Then
    Response.Write Server.HtmlEncode("status = 200, OK!") & "<br>"
Else
    Response.Write Server.HtmlEncode("HTTP Response status = " _
         & status) & "<br>"

    '  Display the complete response header.
    Response.Write Server.HtmlEncode(http.LastResponseHeader) & "<br>"
End If

'  Now try it without following redirects:
Response.Write Server.HtmlEncode("-------- Now trying without following redirects....") & "<br>"
http.FollowRedirects = 0

'  Send the HTTP GET and return the content in a string.
html = http.QuickGetStr(url)
If (html = vbNullString ) Then
    '  the HTML string can NULL if a 302 redirect response is received.
    Response.Write Server.HtmlEncode("HTML string returned NULL...") & "<br>"
End If

'  On success, LastErrorText will provide information about
'  what happened during the call.
Response.Write Server.HtmlEncode("--------------- LastErrorText ------------------") & "<br>"
Response.Write Server.HtmlEncode(http.LastErrorText) & "<br>"
Response.Write Server.HtmlEncode("------------------------------------------------") & "<br>"

'  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 Server.HtmlEncode("This was a redirect response") & "<br>"

    '  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 Server.HtmlEncode("Redirect URL:") & "<br>"
    Response.Write Server.HtmlEncode(http.FinalRedirectUrl) & "<br>"

Else
    Response.Write Server.HtmlEncode("Not redirected.") & "<br>"
End If

status = http.LastStatus
If (status = 200) Then
    Response.Write Server.HtmlEncode("status = 200, OK!") & "<br>"
Else
    Response.Write Server.HtmlEncode("HTTP Response status = " _
         & status) & "<br>"

    '  Display the complete response header.
    Response.Write Server.HtmlEncode(http.LastResponseHeader) & "<br>"
End If

%>
</body>
</html>

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.