2017-03-06 64 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

是的,它是真的......它的实际用户名和密码种类 –