我想從第三方索取報告,他們需要「基本訪問認證」通過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