简体   繁体   中英

“An error occurred while sending the request”, GetAsync(), Xamarin Forms

Like in the title. I have problem with this error. Im trying to make mobile app that will connect to "remote" DB. I was using some tips from all internet and i was looking also here but couldn't find the solution.

Main problem i have right now is with RestClient - that throws this error. WebService is working correctly as it shows in browser xml file and MVC5 Controller also take the data from DB correctly.

Code took from NuGetPack named "Plugin.RestClient":

private const string WebServiceUrl = "http://localhost:50397/api/books/";

    public async Task<List<T>> GetAsync()
    {
        try
        {
            var httpClient = new HttpClient();
            var json = await httpClient.GetStringAsync(WebServiceUrl);

            var taskModels = JsonConvert.DeserializeObject<List<T>>(json);
            return taskModels;
        }
        catch (HttpRequestException e)
        {
            String blad = e.InnerException.Message;
            blad += "asdasd";
        }
        return null;
    }

I'd like to get right connection with db to see in ListView data from server. For now... im just getting blank list and after write the try/catch i saw that there is Message:

"An error occurred while sending the request"

OK, I solve this a while ago... I was working on serv that that doesn't supports the MVC. I created sev on Azure and move MySQL database there. Wrote connectionString like this:

<add name="booksContext" connectionString="Database=booklabdb; Data Source=eu-cdbr-azure-west-b.cloudapp.net; User Id=XXXXX; Password=XXXXX;"
  providerName="MySql.Data.MySqlClient" />

And it's working now :)

Thx for help guys. Hope it'll help someone else ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM