我使用以下代码调用WCF服务:
string certPath = @"C:\certs\mycert.pem";
var uri = new Uri("http://Myserver/TestService.svc/MyMethod/parm1/parm2");
X509Certificate cert = X509Certificate.CreateFromCertFile(certPath);
var request = WebRequest.Create(uri) as HttpWebRequest;
request.Credentials = new NetworkCredential("user", "password");
request.PreAuthenticate = true;
request.ClientCertificates.Add(cert);
var response = request.GetResponse();
但是
HTTP / 1.1 400错误请求
错误和
没有代理验证标头
有人可以指出我正确的方向吗?
答案 0 :(得分:0)
我建议你试试
string urlAddress = "http://www.google.com";
string userName = "user01";
string password = "puser01";
string proxyServer = "127.0.0.1";
int proxyPort = 8081;
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(urlAddress);
if (userName != string.Empty)
{
request.Proxy = new WebProxy(proxyServer, proxyPort)
{
UseDefaultCredentials = false,
Credentials = new NetworkCredential(userName, password)
};
string basicAuthBase64 = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(string.Format("{0}:{1}", userName, password)));
request.Headers.Add("Proxy-Authorization", string.Format("Basic {0}", basicAuthBase64));
}