2017-03-06 61 views
1

網絡憑證請求如何發送HTTPS/HTTP在C#與去

var uri = new Uri("https://demo.com/"); 
 
       var encoding = new UTF8Encoding(); 
 
       var request = (HttpWebRequest)WebRequest.Create(uri); 
 
       request.Method = "POST"; 
 

 
       request.Credentials = new NetworkCredential(utility.commonkey, utility.commonsecrerkey); 
 
       request.ContentType = "application/json"; 
 
       request.Accept = "application/vnd.demo+json;version=3;"; 
 
       request.ContentLength = encoding.GetByteCount(json); 
 
       request.Headers.Add("data", json); 
 
       HttpWebResponse response = null;

,並在旅途中我只能添加添加這些

req.Header.Set("Content-Type", "application/json") 
 
\t req.Header.Set("Authorization", "Basic sdfsfscefewfewfew") 
 
\t req.Header.Set("Accept", "application/vnd.demo+json; version=3;")

這裏在去ch allenge是如何添加網絡憑據中去

+0

?只要'sdfsfscefewfewfew'對應於base64中的'user:password',這應該可以正常工作。 – Havelock

+0

需要添加request.Credentials = new NetworkCredential(utility.commonkey,utility.commonsecrerkey);也不知道如何去做 –

+0

@Havelock,其中請求參數我應該添加此網絡證書....請參閱上面的C#代碼... –

回答

0

從我在the C# docs看到你所指的作爲鍵,只能是用戶名和密碼。您可以使用模擬http.Requestmethod來設置基本身份驗證的用戶名和密碼。

// username has the same value as utility.commonkey 
// password is the corresponding password in plain text 
req.SetBasicAuth(username, password); 

不要忘記從你的Go代碼中刪除以下行還有那麼究竟是什麼問題,你遇到

req.Header.Set("Authorization", "Basic sdfsfscefewfewfew") 
+0

是的,它是真的......它的實際用戶名和密碼種類 –