调用该方法时,它返回状态代码:not found
。我确信uri是正确的,所以我认为问题在于内容。这是终端呼叫的api:
curl --request POST 'https://api.uniparthenope.it/user/radius/auth' --data "user=xxxxxxxxxx" --data "passw=xxxxxxxxxx"
这是我的代码:
public async Task<string> Login()
{
client = new HttpClient();
client.BaseAddress = new Uri("https://api.uniparthenope.it");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.MaxResponseContentBufferSize = 256000;
content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string,string>("user",Username),
new KeyValuePair<string,string>("passw",Password)
});
content.Headers.ContentType.CharSet = "UTF-8";
content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
var response = await client.PostAsync("user/radius/auth", content);
//return response.RequestMessage.ToString();
return response.StatusCode.ToString();
}