为什么我不能像这样调用Web服务方法:
ws test = new ws();
test.Credentials = new NetworkCredential("UserName", "Password");
var temp = test.Method(1, "test");`
但是这项工作:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("url");
req.Credentials = new NetworkCredential("UserName", "Password");
using (WebResponse response = req.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string result= reader.ReadToEnd();
}
}
Web服务使用https。
我收到此错误:
System.Net.WebException:请求失败,HTTP状态为403:Forbidden。