Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to authenticate via HTTPS in code
Message
From
19/07/2003 05:53:46
Keith Payne
Technical Marketing Solutions
Florida, United States
 
 
To
18/07/2003 17:10:11
General information
Forum:
ASP.NET
Category:
Web forms
Miscellaneous
Thread ID:
00811695
Message ID:
00811752
Views:
10
>Hey! My first post to the .Net forum (I'm mostly a FoxPro guy and not much of one at that)...
>
>So, I need to do an HTTPS POST in VB.Net (code follows). The server I'm posting to will only respond with basic error information, but enough for me to know that I'm not authenticating. I'm wondering if anyone has a few lines of code they wouldn't mind sharing or if someone could tell me what's wrong with mine.
>
>TIA,
>Paul
>==========
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
>
> Dim webReq As HttpWebRequest
> Dim webResp As HttpWebResponse
> Dim sr As StreamReader
> Dim sw As StreamWriter
> Dim strTemp As String
>
> strTemp = "login=abc"
>
> webReq = CType(WebRequest.Create("http://www.domainname.com/somescript.asp"), HttpWebRequest)
> webReq.Method = "POST"
> webReq.ContentLength = strTemp.Length
> webReq.Timeout = 5000
> webReq.ContentType = "multipart/form-data"
>
> sw = New StreamWriter(webReq.GetRequestStream)
> sw.Write(strTemp)
> sw.Close()
>
> webResp = webReq.GetResponse
> sr = New StreamReader(webResp.GetResponseStream)
>
> txtResponseC.Text = sr.ReadToEnd.Trim
> sr.Close()
> webResp.Close()
>
> End Sub

Depending on the service provider, you will have to use your network credentials or a client certificate to connect to the resource. For network credentials, add webReq.Credentials = System.Net.CredentialCache.DefaultCredentials to the other statements that are setting the properties of the HttpWebRequest.

If the service provider sent you a client certificate file, the process is a little more complex. Basically, you have to create an X509Certificate from the file they sent you. Then you add the certificate the the HttpWebRequest before posting it. There are many samples out there, most of them are C#, but can be easily translated to VB.NET. I did a google on X509Certificate HTTPS ".NET" and found a ton of hits.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform