我試圖確定爲什麼在使用HTTPS而不是來自Windows Server 2012 R2的HTTP時,對Restful API端點的調用失敗。當我在我的筆記本電腦上本地運行應用程序時(Windows 7),同樣的HTTPS調用起作用。底層連接已關閉 - API端點調用失敗
不幸的是,我不能讓提琴手顯示從Web服務器上的應用程序到API的調用。 試圖枚舉AppContainers列表的AppContainer Loopback Exemption Utility錯誤。服務器也被組策略鎖定,所以我無法關閉防火牆來嘗試解決提琴手問題。
到API的調用是:收到
public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request)
{
client = new HttpClient();
// removed code for setting ignoreCertErrors and environmentName
if (ignoreCertErrors && environmentName.ToUpper() != "PROD")
{
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
}
return client.SendAsync(request);
}
錯誤:
================================================================= Message: The underlying connection was closed: An unexpected error occurred on a send. Stack Trace:
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResultar)================================================================= Message: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. Stack Trace:
at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)================================================================= Message: An existing connection was forcibly closed by the remote host Stack Trace:
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)=================================================================
如何獲得更多的細節?我試圖避免像Wireshark這樣的低級工具,我希望有選項跟蹤/日誌/捕獲有關API失敗的應用程序調用的更多細節。
更新 - 這裏是追蹤信息時失敗:
System.Net Information: 0 : [2292] SecureChannel#49584532::.ctor(hostname=XX.XX.com, clientCertificates=0, encryptionPolicy=RequireEncryption)
System.Net Information: 0 : [2292] SecureChannel#49584532 - Left with 0 client certificates to choose from.
System.Net Information: 0 : [2292] Using the cached credential handle. System.Net Information: 0 : [2292] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = (null), targetName = XX.XX.com, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation) System.Net Information: 0 : [2292] InitializeSecurityContext(In-Buffer length=0, Out-Buffer length=178, returned code=ContinueNeeded).
System.Net.Sockets Verbose: 0 : [2292] Socket#14347911::BeginSend()
System.Net.Sockets Verbose: 0 : [2292] Exiting Socket#14347911::BeginSend() -> OverlappedAsyncResult#19699911 System.Net.Sockets Verbose: 0 : [2292] Data from Socket#14347911::PostCompletion
[ Removed ]
System.Net.Sockets Verbose: 0 : [2292] Socket#14347911::EndSend(OverlappedAsyncResult#19699911)
System.Net.Sockets Verbose: 0 : [2292] Exiting Socket#14347911::EndSend() -> Int32#178
System.Net.Sockets Verbose: 0 : [2292] Socket#14347911::BeginReceive()
System.Net.Sockets Verbose: 0 : [2292] Exiting Socket#14347911::BeginReceive() -> OverlappedAsyncResult#2389992
System.Net.Sockets Verbose: 0 : [2292] Socket#14347911::EndReceive(OverlappedAsyncResult#2389992)
System.Net.Sockets Error: 0 : [2292] Socket#14347911::UpdateStatusAfterSocketError() - ConnectionReset
System.Net.Sockets Error: 0 : [2292] Exception in Socket#14347911::EndReceive - An existing connection was forcibly closed by the remote host. System.Net.Sockets Verbose: 0 : [2292] Exiting Socket#14347911::EndReceive() -> Int32#0
System.Net.Sockets Verbose: 0 : [2292] Socket#14
對api的調用可能失敗。當您連接到服務器時,您使用的訪客權限通常不具有在服務器上運行api的憑據。必須將api安裝在服務器上才能以管理員權限運行。爲了驗證我是正確的,我將檢查服務器上的事件查看器以獲取有關該錯誤的更多詳細信息。 – jdweng
對使用HTTP的API的調用起作用,但是當我切換API URI時使用HTTPS會引發上述錯誤。 – Josh
你測試空響應嗎?不確定的根本原因,但我懷疑你可能會得到空包。 – jdweng