2016-06-08 12 views
5

मैं इस त्रुटि का परीक्षण करने के लिए बस एक नया विंडोज 8.1 ऐप बना रहा हूं।HttpClient.GetStringAsync (url) फेंकना "अंतर्निहित कनेक्शन बंद था: प्रेषण पर एक अनपेक्षित त्रुटि आई।" विंडोज 8.1 सी #

private async void TestMethod() 
     { 
      try 
      {      
       HttpClient httpClient = new HttpClient(); 
       HttpResponseMessage response = await httpClient.GetAsync("https:// url ");      
      } 
      catch (HttpRequestException e) 
      { 
       string s = e.InnerException.Message; 
      } 
     } 

यह हमेशा पकड़ में प्रवेश करने और फेंक है: एप्लिकेशन केवल एक ही कार्य है "अंतर्निहित कनेक्शन बंद कर दिया गया था:। एक अनपेक्षित त्रुटि एक भेजें पर हुई" मुझे बहुत सारे प्रश्नों का जिक्र मिला, लेकिन मेरे लिए कोई समाधान नहीं हुआ क्योंकि यह विंडोज 8.1 स्टोर ऐप एक एएसपी.NET ऐप नहीं है।

उरी मैं ब्राउज़र में खुलता हूं और बहुत अच्छी तरह से काम कर रहा हूं।

मुझे यह लेख भी मिला: https://support.microsoft.com/en-us/kb/915599 लेकिन कोई समाधान नहीं। किसी ने पहले इस समस्या को घेर लिया है?

संपादित करें:

मैं पद्धति को बदल कर async Task

 
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host 
    at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) 
    at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) 
    --- End of inner exception stack trace --- 
    at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) 
    at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult) 
    at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) 
    --- End of inner exception stack trace --- 
    at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 
    at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) 
    --- End of inner exception stack trace --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() 
    at HttpRequestTestApp.MainPage.d__0.MoveNext() 
+0

क्या आपने किसी अन्य यूआरएल एंडपॉइंट्स को आजमाया है? क्या आपको एक ही त्रुटि मिल रही है? –

+1

* पूर्ण * अपवाद पोस्ट करें (यानी 'e.ToString() 'का उपयोग करें), न केवल आंतरिक अपवाद का संदेश। प्रतिक्रिया के स्टेटस कोड भी देखें। क्या यह 4xx, 5xx है? कच्चे अनुरोध और सर्वर प्रतिक्रिया को कैप्चर करने के लिए फिडलर का उपयोग करें। यदि सर्वर क्रैश हो जाता है और पूर्ण प्रतिक्रिया भी नहीं देता है, तो क्लाइंट कोड बदलने में कोई बात नहीं है। –

+2

पीएस आप इस विधि को कैसे कॉल कर रहे हैं? 'async शून्य' का अर्थ है "आग और भूलना"। इसका इंतजार नहीं किया जा सकता है। परीक्षण पूरा होने से पहले आपका प्रोग्राम या टेस्ट फ्रेमवर्क शायद समाप्त हो जाता है। इसके बजाए 'async कार्य' का प्रयोग करें। इवेंट हैंडलर या इसी तरह के तरीकों के लिए 'async void' का उपयोग किया जाना चाहिए केवल –

उत्तर

2

उपयोग करने के लिए यह पता चला मैं Windows.Net.Http उपयोग कर रहा था कि TLS1.2 समर्थन नहीं करता। विंडोज़ वेब। एचटीपी करता है।

+0

'System.Net.Http' –

संबंधित मुद्दे

 संबंधित मुद्दे