我正在开发一个发送http请求的应用程序(在C#中)。 只要没有涉及身份验证的代理服务器,一切正常。
这是我的代码:
request = (HttpWebRequest) WebRequest.Create(uri);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = length;
request.Proxy.Credentials = new NetworkCredential("hans", "maulwurf");
request.Credentials = new NetworkCredential("hans", "maulwurf");
using (var requestStream = request.GetRequestStream())
{
// now send it
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Flush();
requestStream.Close();
}
WebResponse webResponse = request.GetResponse();
在最后一行,我总是得到407.凭证在ie / ff。
中工作有没有人有问题可能是什么? 非常感谢任何帮助!
答案 0 :(得分:1)
我认为您可能还需要指定代理服务器。像这样,例如,
IWebProxy proxy = new WebProxy("<Server IP>", <Server Port>);
proxy.Credentials = new NetworkCredential("hans", "maulwurf");
request.Proxy = proxy;