我想从第三方请求报告,他们需要通过 POST 进行“基本访问身份验证”:
Your client application must use Basic Access Authentication to send the user name and password.
有人能指出我正确的方向吗?
编辑:我确实看到了 this post但有两个答案,我不确定这是否是我需要做的,或者哪个是首选方法。
最佳答案
假设您使用 WebRequest,您将 CredentialCache 附加到您的请求:
NetworkCredential nc = new NetworkCredential("user", "password");
CredentialCache cc = new CredentialCache();
cc.Add("www.site.com", 443, "Basic", nc);
WebRequest request = WebRequest.Create("https://www.site.com");
request.Credentials = cc;
request.PreAuthenticate = true;
request.Method = "POST";
// fill in other request properties here, like content
WebResponse respose = request.GetResponse();
关于C# SSL 基本访问认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1127223/