“底层连接已关闭:发送时发生意外错误."使用 SSL 证书 [英] "The underlying connection was closed: An unexpected error occurred on a send." With SSL Certificate
问题描述
我收到此异常
底层连接已关闭:发送时发生意外错误.
The underlying connection was closed: An unexpected error occurred on a send.
在我的日志中,它随机破坏了我们的 OEM 与我们的电子邮件营销系统的集成.(1-4 小时不等)
in my logs, and it is breaking our OEM integration with our e-mail marketing system at random times. (varying from 1-4 hours)
我的网站托管在带有 IIS 7.5.7600 的 Windows Server 2008 R2 上.
My website is hosted on a Windows Server 2008 R2 with IIS 7.5.7600.
这个网站有大量的 OEM 组件,以及全面的仪表板.除了我们在仪表板中用作 iframe 解决方案的电子邮件营销组件之一外,网站的所有其他元素都可以正常工作.
This website has a large number of OEM components, and comprehensive dashboard. Everything works fine with all the other elements of the website except with one of our e-mail marketing component which we are using as an iframe solution within our dashboard.
它的工作方式是,我发送一个HttpWebRequest 对象与所有凭据,然后我得到一个 url,我将其放入 iframe 中并且它可以工作.
The way it works is, I send a HttpWebRequest object with all the credentials, and I get a url back which I put in an iframe and it works.
但它只能工作一段时间(1-4 小时),然后从调用到
But it only works for some time (1-4 hours), and then from the call to
我得到了异常
底层连接已关闭:发送时发生意外错误.
The underlying connection was closed: An unexpected error occurred on a send.
即使系统尝试从 httpWebRequest 获取 URL,它也会因相同的异常而失败.
Even if the system tries to get the URL from the httpWebRequest it fails with the same exception.
让它再次工作的唯一方法是:
The only way to make it work again is:
- 回收应用程序池
- 在 web.config 中编辑任何内容.
我真的用尽了我能想到的所有选项.
I am really exhausted all the option that i could think of.
明确添加,
keep-alive = false
keep-alive = true
增加超时:
我已将此页面上传到非 SSL 网站,以检查我们生产服务器上的 SSL 证书是否正在断开连接.
I have uploaded this page to a non SSL website to check if the SSL certificate on our production server is making the connection to drop some how.
非常感谢任何解决问题的方向.
Any direction toward resolution is greatly appreciated.
Public Function CreateHttpRequestJson(ByVal url) As String
Try
Dim result As String = String.Empty
Dim httpWebRequest = DirectCast(WebRequest.Create("https://api.xxxxxxxxxxx.com/api/v3/externalsession.json"), HttpWebRequest)
httpWebRequest.ContentType = "text/json"
httpWebRequest.Method = "PUT"
httpWebRequest.ContentType = "application/x-www-form-urlencoded"
httpWebRequest.KeepAlive = False
'ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
'TODO change the integratorID to the serviceproviders account Id, useremail
Using streamWriter = New StreamWriter(httpWebRequest.GetRequestStream())
Dim json As String = New JavaScriptSerializer().Serialize(New With { _
Key .Email = useremail, _
Key .Chrome = "None", _
Key .Url = url, _
Key .IntegratorID = userIntegratorID, _
Key .ClientID = clientIdGlobal _
})
'TODO move it to the web.config, Following API Key is holonis accounts API Key
SetBasicAuthHeader(httpWebRequest, holonisApiKey, "")
streamWriter.Write(json)
streamWriter.Flush()
streamWriter.Close()
Dim httpResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
Using streamReader = New StreamReader(httpResponse.GetResponseStream())
result = streamReader.ReadToEnd()
result = result.Split(New [Char]() {":"})(2)
result = "https:" & result.Substring(0, result.Length - 2)
End Using
End Using
Me.midFrame.Attributes("src") = result
Catch ex As Exception
objLog.WriteLog("Error:" & ex.Message)
If (ex.Message.ToString().Contains("Invalid Email")) Then
'TODO Show message on UI
ElseIf (ex.Message.ToString().Contains("Email Taken")) Then
'TODO Show message on UI
ElseIf (ex.Message.ToString().Contains("Invalid Access Level")) Then
'TODO Show message on UI
ElseIf (ex.Message.ToString().Contains("Unsafe Password")) Then
'TODO Show message on UI
ElseIf (ex.Message.ToString().Contains("Invalid Password")) Then
'TODO Show message on UI
ElseIf (ex.Message.ToString().Contains("Empty Person Name")) Then
'TODO Show message on UI
End If
End Try
End Function
Public Sub SetBasicAuthHeader(ByVal request As WebRequest, ByVal userName As [String], ByVal userPassword As [String])
Dim authInfo As String = Convert.ToString(userName) & ":" & Convert.ToString(userPassword)
authInfo = Convert.ToBase64String(Encoding.[Default].GetBytes(authInfo))
request.Headers("Authorization") = "Basic " & authInfo
End Sub
推荐答案
对我来说是 tls12:
For me it was tls12:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
这篇关于“底层连接已关闭:发送时发生意外错误."使用 SSL 证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!