401 Unauthorized

Hey there, i'm trying to get data from API that has Authentication the API is working fine in Postman i'm using visual studio 2015 and xamarin forms

       var client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
        var json=  await client.GetStringAsync("http://tracker-magconsulting.azurewebsites.net/api/reports/getVisitDetails/2019-03-01/2019-03-13");
        var reports = JsonConvert.DeserializeObject<List<CustomerTaskCount>>(json);
        return reports;
Tagged:

Answers

  • JohnHJohnH GBMember ✭✭✭✭✭

    @Ranamuhammad.1569 said:
    Hey there, i'm trying to get data from API that has Authentication the API is working fine in Postman i'm using visual studio 2015 and xamarin forms

           var client = new HttpClient();
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
            var json=  await client.GetStringAsync("http://tracker-magconsulting.azurewebsites.net/api/reports/getVisitDetails/2019-03-01/2019-03-13");
            var reports = JsonConvert.DeserializeObject<List<CustomerTaskCount>>(json);
            return reports;
    

    Are you sure it is expecting a get not a post?
    When using postman where are you getting your bearer token from? Can you test using the exact same token?

Sign In or Register to comment.