[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 815
  • Last Modified:

HttpWebResponse From a secure site using https

hi all
i am trying to post info to a site using WebRequest / HttpWebResponse it works fine when the request is to http like this

Dim req As Net.HttpWebRequest = Net.WebRequest.Create("http://mail.google.com/mail/#inbox")
Dim WebResult As Net.HttpWebResponse = req.GetResponse()

but when i try the same thing with https like this

Dim req As Net.HttpWebRequest = Net.WebRequest.Create("https://mail.google.com/mail/#inbox")
Dim WebResult As Net.HttpWebResponse = req.GetResponse()

then it dose work when i test the code on the server from ://localhost/
but hen i try to run it from the client from ://server.com/ it gives me this error

A system call that should never fail has failed

i tried to add this line

 Net.ServicePointManager.CertificatePolicy = New MyPolicy 'see the class blow  

but no luck

im using vista home, and iis
so please help
thanks


Imports System.Net
Imports System.Security.Cryptography.X509Certificates
 
Public Class MyPolicy
    Implements ICertificatePolicy
 
    Public Function CheckValidationResult(ByVal srvPoint As System.Net.ServicePoint, ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal request As System.Net.WebRequest, ByVal certificateProblem As Integer) As Boolean Implements System.Net.ICertificatePolicy.CheckValidationResult
        Return True
    End Function
End Class

Open in new window

0
mbacs
Asked:
mbacs
  • 3
  • 3
1 Solution
 
oobaylyCommented:
Have you set the System.Net.ServicePointManager.CertificatePolicy property to equal an instance of the MyPolicy class?

Note however that System.Net.ServicePointManager.CertificatePolicy has been deprecated in .Net v.2 and that the System.Net.ServicePointManager.ServerCertificateValidationCallback property should be used instead:
http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback.aspx
http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/c98ea134-c582-4c2a-8c42-d7e31f7fe389/
'' Set the ServerCertificateValidationCallback
System.Net.ServicePointManager.ServerCertificateValidationCallback = _
          New System.Net.Security.RemoteCertificateValidationCallback(AddressOf ValidateCertificate)
 
 
    Private Function ValidateCertificate(ByVal sender As Object, _
      ByVal certificate As Security.Cryptography.X509Certificates.X509Certificate, _
      ByVal chain As Security.Cryptography.X509Certificates.X509Chain, _
      ByVal sslPolicyErrors As System.Net.Security.SslPolicyErrors) As Boolean
      '' Allow anything with no errors
      If (sslPolicyErrors = System.Net.Security.SslPolicyErrors.None) Then Return True
 
      '' Allow any requests to mydomain.com
      If (sender.GetType() Is GetType(System.Net.HttpWebRequest)) Then
        If (CType(sender, System.Net.HttpWebRequest).Address.Host = "mydomain.com") Then
          Return True
        End If
      End If
 
      Return False
    End Function

Open in new window

0
 
mbacsAuthor Commented:
still get the same error

A system call that should never fail has failed

Server Error in '/EZVoice' Application.
A system call that should never fail has failed
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
 
Exception Details: System.Net.Sockets.SocketException: A system call that should never fail has failed
 
Source Error:
 
Line 21:         
Line 22:         'Net.ServicePointManager.CertificatePolicy = New MyPolicy
Line 23:         Dim WebResult As Net.HttpWebResponse = req.GetResponse()
Line 24: 
Line 25:     End Sub
 
 
Source File: C:\Users\Moishe\Documents\Visual Studio 2005\WebSites\EzVoice\test.aspx    Line: 23
 
Stack Trace:
 
[SocketException (0x277b): A system call that should never fail has failed]
   System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +73
   System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +131
 
[IOException: Unable to read data from the transport connection: A system call that should never fail has failed.]
   System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +294
   System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count) +37
   System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +73
   System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +49
   System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +137
   System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) +53
   System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) +120
   System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +85
   System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +49
   System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +137
   System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) +53
   System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) +120
   System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +85
   System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +49
   System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +137
   System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) +53
   System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) +120
   System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +85
   System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +49
   System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +137
   System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) +143
   System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) +99
   System.Net.TlsStream.CallProcessAuthentication(Object state) +47
   System.Threading.ExecutionContext.runTryCode(Object userData) +80
   System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) +0
   System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) +102
   System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) +68
   System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) +746
   System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) +58
   System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) +26
   System.Net.ConnectStream.WriteHeaders(Boolean async) +124
 
[WebException: The underlying connection was closed: An unexpected error occurred on a send.]
   System.Net.HttpWebRequest.GetResponse() +5314029
   ASP.test_aspx.Button1_Click(Object sender, EventArgs e) in C:\Users\Moishe\Documents\Visual Studio 2005\WebSites\EzVoice\test.aspx:23
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
 
 
Version Information: Microsoft .NET Framework Version:2.0.50727.3074; ASP.NET Version:2.0.50727.3074 

Open in new window

0
 
oobaylyCommented:
Two things:
Why is the Net.ServicePointManager.CertificatePolicy line commented out?
Is the server permitted to make outbounds requests to TCP port 443 (https)?
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
mbacsAuthor Commented:
the Net.ServicePointManager.CertificatePolicy line is commented out because i used  ServerCertificateValidationCallback  like you said

and how do i know if the server is permitted to make outbound requests to TCP port 443

it dose work when i run the page on the server using localhost but it dose not when i run the page from the client or server using Server_Domain.Com
so i think it dose have to do something with permission for IIS to make the request

so how do i check and how do i change this

keep in mind that the server is  windows vista home premium running iis 7.0

0
 
oobaylyCommented:
Sorry, missed the bit about http://localhost, so scrap the comment about firewalled outbound connections. I'm afraid I've never used IIS on Vista, so it's possible there are some permission issues, but I can't really comment.
Interestingly, there are only three pages returned by google containing the error message "A system call that should never fail has failed" and HttpWebRequest, and appear to be referring to the Compact Framework.

I'd suggest adding the Vista & IIS zones to this question.
0
 
mbacsAuthor Commented:
ok so i changed server and i am using now windows xp and it works fine so when Bill Gates decides to take off that wonderful feature from vista ill think of changing back
 
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now