I am studying the course XAM150 to do with REST, and I get WebExceptionStatus.NameResolutionFailure

I am studying the Xamarin University course XAM150 to learn about REST.
For exercise 2, with this code;

    private string authorizationKey;
    private const string Url = "http: //xam150 .azurewebsites.net/api/books/";

    private async Task<HttpClient> GetClient()
    {
        var client = new HttpClient();
        if (string.IsNullOrEmpty(authorizationKey))
        {
            try
            {
                var token = await client.GetStringAsync(Url + "login");
                authorizationKey = JsonConvert.DeserializeObject<string>(token);
            }
            catch (Exception ex)
            {
                var i = 0;
            }
        }

The line ; var token = await client.GetStringAsync(Url + "login");
Throws an exception;
System.Net.WebExceptionStatus.NameResolutionFailure

When I take the url and paste it into a browser I get the authorizationKey as a Guid OK.
So how do I fix this?

Tagged:

Answers

  • wesleyfavarinwesleyfavarin USMember ✭✭

    Hi

    @GeoffreyPayne

    you not need sent the token ?

    your url contains spaces, remove the spaces, maybe it is that
    "http: //xam150 .azurewebsites.net/api/books/"

    let me know if it's right.

  • arame3333arame3333 GBMember ✭✭
    edited February 2018

    I had to put spaces in the url in order to post the question. In my code they do not exist. As a new member of this forum I am not allowed to post links.

  • Gigex42Gigex42 USMember ✭✭✭✭

    Did you try calling your webseite from the webbrowser? Does it give any error?

    Also it sounds like it cannot resolve the host name. Try IP instead to test if it works.

  • arame3333arame3333 GBMember ✭✭
    edited February 2018

    In my question I mention that I put the url in my browser and I get a valid response. You can try it too. However I do not know the IP address of the url.

Sign In or Register to comment.