1
Answer

Getting response "System.Net.HttpStatusCode.Unauthorized"

Shefali Lahariya

Shefali Lahariya

6y
209
1
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)