Barbara Pušnar
Barbara Pušnar

Reputation: 1

httpclient getasync method fails on some networks

I wrote a Xamarin Forms application. It uses HttpClient. Code of my method is

 public static async Task<List<CarshareList>> SearchRidesAsync(string fromCity, string toCity, DateTime date, string type = "shares", CancellationToken token = default(CancellationToken))
    {
        using (var client = new HttpClient())
        {
            string s = "https://prevoz.org/api/search/shares/?";
            s += "f=" + fromCity+"&";
            s += "fc=SI" + "&";
            s += "t=" + toCity + "&";
            s += "tc=SI"  + "&";
            s += "d=" + date.ToString("yyyy-MM-dd");
            var z = await client.GetAsync(new Uri(s));
            List<CarshareList> moj = new List<CarshareList>();
            var y = await z.Content.ReadAsAsync<CarshareResponse>();
            foreach (var a in y.CarshareList)
                    moj.Add(a);
            return moj;
        }
    }

When I call the service from my laptop at home network I receive results in UWP and Android application (can't test for iOS). It all works fine. When I run the same code (same laptop) at school I don't receive any result. I've tried to debug my project and in line

  var z = await client.GetAsync(new Uri(s));

returns to MainPage. This happens always in school. z doesn't have any return code. If I copy URL for my call in web browser (at school) I get the normal JSON results. What am I missing? Thanks, Barbara

Upvotes: 0

Views: 322

Answers (0)

Related Questions