在PB下怎样可以调用HTTPS双向认证的证书?有一段C#的例程,但PB不道应该怎样用。
3、C#使用证书
C#使用证书默认使用操作系统以导入的证书,即在操作系统上按装apiclient_cert.p12即可。C#也可以忽略其他三个pem文件。
使用如下:
string cert = @"R:\apiclient_cert.p12";
string password = "10010000";
ServicePointManager.ServerCertificateValidationCallback=new RemoteCertificateValidationCallback(CheckValidationResult);
X509Certificate cer = new X509Certificate(cert, password);
HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(url);
webrequest.ClientCertificates.Add(cer);
webrequest.Method = "post";
HttpWebResponse webreponse = (HttpWebResponse)webrequest.GetResponse();
Stream stream = webreponse.GetResponseStream();
/*CheckValidationResult的定义*/
private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
if (errors == SslPolicyErrors.None)
return true;
return false;
}
注意:C#有一点需要注意,除了在代码中使用apiclient_cert.p12之外还需要将该证书导入操作系统才能使用,1、代码中使用、;2、导入操作系统,二者缺一不可。.NET版本需要大于2.0
------解决方案--------------------
使用pb的posturl和geturl是无法调用https的,你可以用xmlhttp来实现
------解决方案--------------------
pb与web异步通信(XMLHttp)
oleobject xHttp
string ls_webcode
time time1
time1 = now()
xHttp = create oleobject
xHttp.ConnectToNewObject("Microsoft.XMLHttp")
xHttp.open("get", "www.163.com", true) //false同步,true异步;设置为false时下面的do while循环可以不要。
xHttp.SetRequestHeader("Content-Type", "text/html")
xHttp.send()
do while xHttp.readyState <> 4 //循环查询状态
yield() //释放操作权限
if abs(SecondsAfter(time1, now())) > 2 then //超过2秒无返回,结束本次通信,进入下一周期
xHttp.abort()
return
end if
loop
ls_webcode = xHttp.responseText()
xHttp.DisconnectObject()
destroy xHttp