1

我想将一些数据发布到 https 服务器,在此之前我需要添加客户端证书以进行信任验证。我已经在 C# 中完成了它,如下所示:-

X509Certificate cert = X509Certificate.CreateFromCertFile("Path to my .cer file");   //****** name of cer file is "ServerTrial.cer" ******//
Uri authURL = new Uri("https://myServer/post");
HttpWebRequest authRequest = (HttpWebRequest)WebRequest.Create(authURL);    //****** Here i add the server url ******//
authRequest.ClientCertificates.Add(cert);    //****** Here i add the client certificate ******//
authRequest.Method = "POST";    //****** Here i specify the method which is "POST" ******//

byte[] postBytes = "Data to be posted";
authRequest.ContentLength = postBytes.Length;
Stream requestStream = authRequest.GetRequestStream();
// now send it
requestStream.Write(postBytes, 0, postBytes.Length);   //****** Here I post the data to the Server ******//
requestStream.Close();

// grab the response
HttpWebResponse response = (HttpWebResponse)authRequest.GetResponse();      
StreamReader responseStream = new StreamReader(response.GetResponseStream());
string responseStr = responseStream.ReadToEnd();

所以最终我想要的是创建一个 http 对象,将服务器 url 添加到它,将客户端证书添加到它,然后最后将数据发布到服务器。现在我想在 C++ 中实现上述目标。我正在考虑将 openSSL 用于上述内容,但我对此知之甚少。有人可以指导我吗?

- 谢谢大家,sattu

4

0 回答 0