如何在go中使用网络凭据发送https/http请求

如何在go中使用网络凭据发送https/http请求,go,https,beego,networkcredentials,Go,Https,Beego,Networkcredentials,在c# var uri=新uri(“https://demo.com/"); var encoding=新的UTF8Encoding(); var request=(HttpWebRequest)WebRequest.Create(uri); request.Method=“POST”; request.Credentials=newnetworkcredential(utility.commonkey,utility.commonsecrrkey); request.ContentType=

在c#

var uri=新uri(“https://demo.com/");
var encoding=新的UTF8Encoding();
var request=(HttpWebRequest)WebRequest.Create(uri);
request.Method=“POST”;
request.Credentials=newnetworkcredential(utility.commonkey,utility.commonsecrrkey);
request.ContentType=“application/json”;
request.Accept=“application/vnd.demo+json;version=3;”;
request.ContentLength=encoding.GetByteCount(json);
添加(“数据”,json);
HttpWebResponse响应=null从我所看到的您所指的密钥中,只能是用户名和密码。您可以使用模拟
http.Request
,为基本身份验证设置用户名和密码

// 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")
从我看到的,你们所指的密钥,只能是用户名和密码。您可以使用模拟
http.Request
,为基本身份验证设置用户名和密码

// 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")

那么你有什么问题?只要
sdfsfscefewfewfew
对应于base64中的
user:password
,这应该可以正常工作。需要添加请求。凭据=新的网络凭据(utility.commonkey,utility.commonsecerkey);但也不确定如何在go@Havelock,我应该在请求的哪个参数中添加此网络凭据…请参考上面的c#代码…用
实用程序.commonkey
实用程序.commonsecerkey
表示什么?是用户名和密码吗?这些密钥基本上是…服务器决定使用哪个api的密钥?您遇到了什么问题?只要
sdfsfscefewfewfew
对应于base64中的
user:password
,这应该可以正常工作。需要添加请求。凭据=新的网络凭据(utility.commonkey,utility.commonsecerkey);但也不确定如何在go@Havelock,我应该在请求的哪个参数中添加此网络凭据…请参考上面的c#代码…用
实用程序.commonkey
实用程序.commonsecerkey
表示什么?它是用户名和密码吗?这些密钥基本上是…服务器决定使用哪个api的密钥…它的实际用户名和密码是的,是的…它的实际用户名和密码是