我有例外
基础连接已关闭: 发送时发生意外错误。
在我的日志,它打破了我们的 OEM 整合与我们的电子邮件营销系统随机时间
我的网站是托管在一个 Windows Server 2008 R2与 Iis7.5.7600。
这个网站有大量的 OEM 组件,和全面的仪表板。除了我们的一个电子邮件营销组件之外,所有其他元素都可以很好地工作,我们正在使用它作为仪表板内的 iframe 解决方案。
它的工作方式是,我发送一个带有所有凭证的 < a href = “ https://Learn.microsoft.com/en-us/dotnet/api/system.net.httpwebrerequest? view = net-6.0”rel = “ nofollow noReferrer”> HttpWebRequest 对象,然后我得到一个 URL,我把它放到一个 iframe 中,它就可以工作了。
但它只能工作一段时间(1-4小时) ,然后从调用
我有例外
基础连接已关闭: 发送时发生意外错误。
即使系统尝试从 HttpWebRequest获取 URL,也会出现同样的异常。
唯一的办法就是:
我已经想尽一切办法了。
明确地加上,
keep-alive = false
keep-alive = true
增加了暂停时间:
<httpRuntime maxRequestLength="2097151" executionTimeout="9999999" enable="true" requestValidationMode="2.0" />
我已经上传了这个页面到一个非 SSL 的网站,以检查是否 SSL 证书在我们的生产服务器是使连接下降了一些方式。
任何解决问题的方向都是值得赞赏的。
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