I am trying to post form values to a https web page programmatically
using Httpwebrequest but no matter what I do the same login page is
returned instead of the next page. I would very much appreciate if
someone could show me what is it that I am doing wrong. Below is the
code that I am using.
Expand|Select|Wrap|Line Numbers
- Imports System.IO
- Imports System.Net
- Imports System.Net.Security
- Imports System.Security.Cryptography.X509Certificates
- Public Class Form1
- Private Function ValidateCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
- If certificate.Issuer.Contains("OU=Diadora") Then
- Return True
- Else
- Return False
- End If
- End Function
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)
- Dim Req As HttpWebRequest
- 'Dim SourceStream As System.IO.Stream
- Dim Response As HttpWebResponse
- '-- get file
- Dim URL2 As String = "https://mysite.com:8443/filelist/library.htm?o_id=2"
- Req = HttpWebRequest.Create(URL2)
- Req.Credentials = New NetworkCredential("admin", "password")
- Req.AllowAutoRedirect = False
- Response = Req.GetResponse()
- Dim sr2 As IO.StreamReader = New IO.StreamReader(Req.GetResponse.GetResponseStream)
- '-- check responser, and make sure you are logged in
- Dim html_data As String = sr2.ReadToEnd
- Console.WriteLine(sr2.ReadToEnd)
- Response.Close()
- End Sub
- End Class