VB.NET Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

VB.NET Examples

Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
Email
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
PFX
RSA
S/MIME
SMTP
Socket
Spider
SSH
SSH Tunnel
SSH Key
SFTP
Tar Archive
Upload
XML
XMP
Zip Compression
Misc

More Examples...
Amazon S3
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

Byte Array
VB.NET FTPS
System.IO

 

 

 

 

 

 

HTTP Redirect Handling

Download Chilkat .NET for 4.0 Framework

Download Chilkat .NET for 64-bit 4.0 Framework (x64)

Download Chilkat .NET for 2.0 / 3.5 Framework

Download Chilkat .NET for 64-bit 2.0 / 3.5 Framework (x64)

Download Chilkat .NET for 1.0 / 1.1 Framework

Examine HTTP redirects.

Dim http As New Chilkat.Http()

Dim success As Boolean

'  Any string unlocks the component for the 1st 30-days.
success = http.UnlockComponent("Anything for 30-day trial")
If (success <> true) Then
    MsgBox(http.LastErrorText)
    Exit Sub
End If


Dim url As String
Dim html As String
Dim status As Long

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 = true

'  Send the HTTP GET and return the content in a string.
html = http.QuickGetStr(url)
If (html Is Nothing ) Then
    MsgBox(http.LastErrorText)
End If


'  On success, LastErrorText will provide information about
'  what happened during the call.
TextBox1.Text = TextBox1.Text & "--------------- LastErrorText ------------------" & vbCrLf
TextBox1.Refresh()
TextBox1.Text = TextBox1.Text & http.LastErrorText & vbCrLf
TextBox1.Refresh()
TextBox1.Text = TextBox1.Text & "------------------------------------------------" & vbCrLf
TextBox1.Refresh()

'  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 = true) Then
    TextBox1.Text = TextBox1.Text & "Chilkat HTTP followed the redirect." & vbCrLf
    TextBox1.Refresh()

    '  Display the final redirect URL:
    TextBox1.Text = TextBox1.Text & "Final URL:" & vbCrLf
    TextBox1.Refresh()
    TextBox1.Text = TextBox1.Text & http.FinalRedirectUrl & vbCrLf
    TextBox1.Refresh()

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

Else
    TextBox1.Text = TextBox1.Text & "Not redirected." & vbCrLf
    TextBox1.Refresh()
End If



status = http.LastStatus
If (status = 200) Then
    TextBox1.Text = TextBox1.Text & "status = 200, OK!" & vbCrLf
    TextBox1.Refresh()
Else
    TextBox1.Text = TextBox1.Text & "HTTP Response status = " _
         & status & vbCrLf
    TextBox1.Refresh()

    '  Display the complete response header.
    TextBox1.Text = TextBox1.Text & http.LastResponseHeader & vbCrLf
    TextBox1.Refresh()
End If


'  Now try it without following redirects:
TextBox1.Text = TextBox1.Text & "-------- Now trying without following redirects...." & vbCrLf
TextBox1.Refresh()
http.FollowRedirects = false

'  Send the HTTP GET and return the content in a string.
html = http.QuickGetStr(url)
If (html Is Nothing ) Then
    '  the HTML string can NULL if a 302 redirect response is received.
    TextBox1.Text = TextBox1.Text & "HTML string returned NULL..." & vbCrLf
    TextBox1.Refresh()
End If


'  On success, LastErrorText will provide information about
'  what happened during the call.
TextBox1.Text = TextBox1.Text & "--------------- LastErrorText ------------------" & vbCrLf
TextBox1.Refresh()
TextBox1.Text = TextBox1.Text & http.LastErrorText & vbCrLf
TextBox1.Refresh()
TextBox1.Text = TextBox1.Text & "------------------------------------------------" & vbCrLf
TextBox1.Refresh()

'  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 = true) Then
    TextBox1.Text = TextBox1.Text & "This was a redirect response" & vbCrLf
    TextBox1.Refresh()

    '  When redirects are not followed, FinalRedirectUrl
    '  contains the redirect URL that would've been taken...
    '  Display the redirect URL, which was not taken...
    TextBox1.Text = TextBox1.Text & "Redirect URL:" & vbCrLf
    TextBox1.Refresh()
    TextBox1.Text = TextBox1.Text & http.FinalRedirectUrl & vbCrLf
    TextBox1.Refresh()

Else
    TextBox1.Text = TextBox1.Text & "Not redirected." & vbCrLf
    TextBox1.Refresh()
End If


status = http.LastStatus
If (status = 200) Then
    TextBox1.Text = TextBox1.Text & "status = 200, OK!" & vbCrLf
    TextBox1.Refresh()
Else
    TextBox1.Text = TextBox1.Text & "HTTP Response status = " _
         & status & vbCrLf
    TextBox1.Refresh()

    '  Display the complete response header.
    TextBox1.Text = TextBox1.Text & http.LastResponseHeader & vbCrLf
    TextBox1.Refresh()
End If

 

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

Mail Component · XML Parser