Shefali Lahariya

Shefali Lahariya

  • NA
  • 257
  • 156.3k

Getting response "System.Net.HttpStatusCode.Unauthorized"

Nov 22 2017 6:08 AM
Hi,
 
i am using below code i am getting response " Getting response "System.Net.HttpStatusCode.Unauthorized""  but its working fine on postman so how to resolve this error.
 
 
public static async Task<string>getDataFromService(string wInputData, string Uri)
{
string json = string.Empty;
using (HttpClient client = new HttpClient())
{
//client.DefaultRequestHeaders.Add("API_KEY", "X-some-key");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Authorization","Basic MzUzYjMwMmM0NDU3NGY1NjUwNDU2ODdlNTM0ZTdkNmE6Mjg2OTI0Njk3ZTYxNWE2NzJhNjQ2YTQ5MzU0NTY0NmM=");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpContent content = new StringContent(wInputData);
content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
var response =await client.PostAsync("http://13.228.72.152:8080/JioMeet/oauth/token",content);
if (response != null)
{
return response.ToString();
//return response.StatusCode;
}
else
{
return "no data";
// return System.Net.HttpStatusCode.BadRequest;
}
}
}
 

Answers (1)