2016-02-25 13 views
14

我打電話第三方服務,當我問一個響應它拋出,說驗證失敗,因爲遠程方已關閉正從web服務

「驗證異常的響應時的傳輸流異常因遠程方已關閉傳輸流異常而失敗「。

我認爲在發送憑證時存在問題。我甚至嘗試提供新的憑據。下面是完整的代碼

 string get_url = "https://**.*******.com/com/******/webservices/public_webservice.cfc?wsdl&Method=CreateUser&SiteID=**&WSPassword=******&UserName=******"; 
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(get_url); 
     request.MaximumAutomaticRedirections = 4; 
     request.MaximumResponseHeadersLength = 4; 
     request.Credentials = CredentialCache.DefaultCredentials; 
     //request.UseDefaultCredentials = false; 
     //request.Credentials = new System.Net.NetworkCredential("*****", "*****"); 
     request.ContentType = "application/x-www-form-urlencoded; charset=ISO-8859-1"; 

     // Show the sent stream 
     //lbl_send_stream.Text = send_stream; 
     //lbl_send_stream.Text = get_url; 
     // Get UserId And LoginToken From Third Party DB 
     // ============================================== 
     //Exception gets throwed When code hits here 
     HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 

enter image description here

+1

http://stackoverflow.com/questions/19639846/failure-on-httpwebrequest-with-inner-exception-authentication-failed-because-the –

+0

我試過了,它並不能解決問題。 –

回答

40

我找到了答案,那是因爲我們叫不支持TLS 1.0的第三方web服務他們支持1.1和1.2。所以我不得不改變安全協議。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; 
+1

我可以在哪裏添加該代碼? –

+2

您可以在從請求獲取HTTPResponse之前添加它。 –

+0

我的SecurityProtocolType不顯示Tls12和Tls11的選項。我正在使用.net框架4. –

相關問題