我想从第三方索取报告,他们需要“基本访问认证”通过POST:C#SSL基本接入认证
Your client application must use Basic Access Authentication to send the user name and password.
有人能指出我在正确的方向?
编辑:我没看到this post,但有两个答案,我不确定这是我需要做什么或哪一个是首选的方法。
我想从第三方索取报告,他们需要“基本访问认证”通过POST:C#SSL基本接入认证
Your client application must use Basic Access Authentication to send the user name and password.
有人能指出我在正确的方向?
编辑:我没看到this post,但有两个答案,我不确定这是我需要做什么或哪一个是首选的方法。
假设你使用的WebRequest,您可以将CredentialCache您的要求:
的基本要点是这样的:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = WebRequestMethods.Http.Get;
request.Credentials = new NetworkCredential(username, password);
但有时也有使用要求的凭证,这些问题替代方案是在请求标头中添加验证数据
string authInfo = username + ":" + password;
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
request.Headers["Authorization"] = "Basic " + authInfo;
f或更多详情,请参见这篇博客文章
http://charlie.cu.cc/2012/05/how-use-basic-http-authentication-c-web-request/
这是你想要的,在该职位接受的答案是做事情的艰辛的道路,但可能需要为自己在做什么。请记住,如果您使用的是代理服务器,则需要通过request.Proxy.Credentials发送单独的凭据另外,如果您使用代理服务器,则可能会/可能无法使用PreAuthenticate。你也不一定要做CredentialCache,你可以设置request.Credentials = nc;不知道有什么区别。 – 2009-07-14 19:06:12