我使用的是一个web API,然后我向webb API验证了自己,并提供了错误的用户名或密码,站点返回"The remote server return an error:(401) username“。这很好。但是该站点也以JSON的形式返回详细信息,但是我找不到如何访问这些信息,于是我得到了一个401异常。
有谁有线索吗?下面是我使用的代码:
private string Post(string data, string URI)
{
string response = string.Empty;
using (var wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
try
{
response = wc.UploadString(URI, data);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
return response;
}谢谢
发布于 2013-03-12 20:57:46
您应该会收到一个WebException。
WebReception有一个
响应
属性,该属性应包含您要查找的内容。您也可以检查所有其他属性。
https://stackoverflow.com/questions/15361721
复制相似问题