2016-08-19 175 views
0

我在VS2015中有一個Xamarin.Forms應用程序項目,它在我的網絡中使用REST服務。 該項目的Android和iOS版本連接並從本地主機和我的網絡中發佈的服務獲取數據,但Windows 8應用程序只在本地主機上工作,當我嘗試從我的網絡中的服務獲取數據時,我只得到這個在輸出控制檯:無法從我的Windows 8.1應用程序發送HTTP請求

Exception thrown: 'System.Net.Http.HttpRequestException' in mscorlib.dll 
       ERROR An error occurred while sending the request. 

是否存在我失蹤的權限或安全限制?

我忘了說,Web服務是在端口5000是這樣的: http://localhost:5000/api/clientshttp://192.168.10.23:5000/api/clients 不知道有關或有任何政策限制在Win8的應用偵聽的端口。

編輯2:

I think I should include the method where the exception is thrown: 

    public async Task<List<Client>> LoadClientsAsync(string query) 
      { 
       var Items = new List<Client>(); 

       // RestUrl = http://192.168.10.100:5000/api/clients{0} 

       var sb = new System.Text.StringBuilder(); 
       sb.Append("?q="); 
       sb.Append(System.Net.WebUtility.UrlEncode(query)); 

       var uri = new Uri(string.Format(Constants.RestUrl, sb.ToString())); 

       try 
       { 

        var response = await httpclient.GetAsync(uri); 
//Here is where exception is thrown 
        if (response.IsSuccessStatusCode) 
        { 
         var content = await response.Content.ReadAsStringAsync(); 
         Items = JsonConvert.DeserializeObject<List<Client>>(content); 
        } 
       } 
       catch (Exception ex) 
       { 
        Debug.WriteLine(@"    ERROR {0}", ex.Message); 
       } 

       return Items; 
      } 

回答

0

因爲試圖發送請求到服務在本地網絡中,啓用「專用網絡(客戶端&服務器)」能力在Package.appxmanifest使其工作。

相關問題