我正在尝试使用本地安装在我的计算机上的X509Certificate2
与外部服务进行通信。当我尝试读取请求流时,我收到一条错误,指出我无法与服务通信。我想知道我的请求是否有任何明显的错误,或者在提出这样的请求时我还应该考虑其他什么。
这是以前在控制台应用程序中工作,我将其移动到一个Web项目。
更新:我在配置中添加了代理设置,这会产生不同的错误。 " ServicePointManager不支持使用https方案"
的代理<defaultProxy>
<proxy usesystemdefault = "false" proxyaddress="https://theserverIamtryingtoreach:{port}" bypassonlocal="false"/>
</defaultProxy>
X509Certificate2 clientCertificate = new X509Certificate2(strMIBPFX, strPwd);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);
request.Method = "POST";
request.ClientCertificates.Add(clientCertificate);
request.PreAuthenticate = true;
request.KeepAlive = true;
request.Credentials = CredentialCache.DefaultCredentials;
string postData = "";
GetRequestXml(objEntity);
postData = GetXml();
string strFileName = _intCounter + "_" + objEntity.PolicyNumber + ".xml";
SaveXMLOnDisk(postData, _strDailyReq + "/" + strFileName);
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/xml;charset=UTF-8";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
strFileName = _intCounter + "_" + objEntity.Number.Trim() + ".xml";
SaveXMLOnDisk(responseFromServer, _strDailyMibRes + "/" + strFileName);
答案 0 :(得分:0)
对我来说,解决方案证明我使用的URL不正确。我还必须确保在我的开发环境中正确安装了证书。之后,我能够使用邮递员发送测试帖,并能够解决问题。