簡體   English   中英

在Xamarin PCL中調用REST API時連接失敗

[英]Connection Failure while calling a REST API in Xamarin PCL

從PCL調用REST API時,應用程序崩潰了。 錯誤1.錯誤:ConnectFailure(連接被拒絕)。 2.跳過1367幀! 該應用程序可能在其主線程上做太多工作。

這是我的代碼。

using (client = new HttpClient())
            {
                try
                {                     

                    var response = await client.GetAsync("http://<my server ip>/Service//DataService.svc/?getVehicleInfo?vehicleId="+ id);

                    if (response.IsSuccessStatusCode)
                    {
                        var content = await response.Content.ReadAsStringAsync();
                        JSONModel jsonVehicle = JsonConvert.DeserializeObject<JSONModel>(content);

                        vehicle = JsonConvert.DeserializeObject<VehicleModel>(jsonVehicle.Result);

                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(@"ERROR {0}", ex.Message);
                }

                return vehicle;
            }

我在GetAsync()中收到此錯誤。 在AndroidManifest.xml中啟用了Internet服務。 這是進一步進行的障礙。 需要幫助來解決它。

在這里看看雙斜杠:Service // DataService.svc。 可能是問題所在。 用。。。來代替 /

嘗試更新Xamarin,第6個版本的xamarin存在非常類似的問題,但第7個問題消失了

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM