我在 .net framework 3.5 项目中使用此代码:
HttpWebRequest request = (HttpWebRequest) HttpWebRequest.Create(ServiceUri);
WebProxy proxy = new WebProxy();
proxy.Address = new Uri(ProxyUri);
proxy.Credentials = new NetworkCredential(userName, pass, domain);
request.Proxy = proxy;
request.Method = "POST";
request.ContentType = "application/xml";
request.Accept = "application/xml";
byte[] content = Encoding.UTF8.GetBytes(xmlRequest.ToString());
request.ContentLength = content.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(content, 0, content.Length);
}
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
最后一行给了我“需要 407 代理身份验证”。但是如果我添加到配置中它会起作用:
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
如何在不使用 clr 4.0 的情况下使其工作?