Hi guys i wrote down the following code to connect to a secure web site using WINHTTP,but i am getting "security error",although i can access some other websites with this code but when i am trying to connect to Secure Web Site with the client certificate i am getting the above error..
Thanks
Nouman
ERROR
=====
System.Runtime.InteropServices.COMException (0x80072F8F): A security error occurred
at WinHttp.WinHttpRequestClass.Send(Object Body)
at SOAPWebApp.WebForm1.btnTest_Click(Object sender, EventArgs e) in C:\Inetpub\ 118
CODE
====
Try
Dim sss As String = ""
Dim HttpReq As New WinHttp.WinHttpRequest
' Open an HTTP connection.
HttpReq.Open("PUT", " False)
If Trim(txtUsername.Text) <> "" And Trim(txtPassword.Text) <> "" Then
HttpReq.SetCredentials(Trim(txtUsername.Text), Trim(txtPassword.Text), 0)
End If
' Select the client certificate.
HttpReq.Option(WinHttp.WinHttpRequestOption.WinHttpRequestOption_SelectCertificate) = "LOCAL_MACHINE\My\Joe's-Software-Emporium"
HttpReq.SetClientCertificate("LOCAL_MACHINE\My\Joe's-Software-Emporium")
' Set Header for SOAP Action
HttpReq.SetRequestHeader("SOAPAction", " HttpReq.SetRequestHeader("Content-Type", "text/xml; charset=utf-8") 'FOR SOAP
HttpReq.SetRequestHeader("Content-Length", Len(sss))
' Send the HTTP Request.
HttpReq.Send()
TextBox1.Text = HttpReq.ResponseText
Catch exp As Exception
TextBox1.Text = "Error Occurred : " & exp.Message & vbCrLf & vbCrLf & exp.GetBaseException.ToString
End Try
Nouman Zaheer
Software Engineer
MSR
Thanks
Nouman
ERROR
=====
System.Runtime.InteropServices.COMException (0x80072F8F): A security error occurred
at WinHttp.WinHttpRequestClass.Send(Object Body)
at SOAPWebApp.WebForm1.btnTest_Click(Object sender, EventArgs e) in C:\Inetpub\ 118
CODE
====
Try
Dim sss As String = ""
Dim HttpReq As New WinHttp.WinHttpRequest
' Open an HTTP connection.
HttpReq.Open("PUT", " False)
If Trim(txtUsername.Text) <> "" And Trim(txtPassword.Text) <> "" Then
HttpReq.SetCredentials(Trim(txtUsername.Text), Trim(txtPassword.Text), 0)
End If
' Select the client certificate.
HttpReq.Option(WinHttp.WinHttpRequestOption.WinHttpRequestOption_SelectCertificate) = "LOCAL_MACHINE\My\Joe's-Software-Emporium"
HttpReq.SetClientCertificate("LOCAL_MACHINE\My\Joe's-Software-Emporium")
' Set Header for SOAP Action
HttpReq.SetRequestHeader("SOAPAction", " HttpReq.SetRequestHeader("Content-Type", "text/xml; charset=utf-8") 'FOR SOAP
HttpReq.SetRequestHeader("Content-Length", Len(sss))
' Send the HTTP Request.
HttpReq.Send()
TextBox1.Text = HttpReq.ResponseText
Catch exp As Exception
TextBox1.Text = "Error Occurred : " & exp.Message & vbCrLf & vbCrLf & exp.GetBaseException.ToString
End Try
Nouman Zaheer
Software Engineer
MSR