Answer the question
In order to leave comments, you need to log in
How to convert code from PHP to C# (SSL request)?
I have a php code that accesses the service via https
$ch = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->server_url);
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_USERAGENT, "User-Agent=Mozilla/5.0 Firefox/1.0.7");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSLCERT, $this->pem_file); //path_file.pem
curl_setopt($curl, CURLOPT_SSLKEY, $this->key_file); //path_file.key
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($curl, CURLOPT_CAINFO, $this->chain_file); //path_file.crt
curl_setopt($curl, CURLOPT_POSTFIELDS, $this->post);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$result_curl = curl_exec($ch);
curl_close($ch);
echo $result_curl;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
HttpWebRequest rq = (HttpWebRequest)WebRequest.Create(server_url);
rq.Method = "POST";
rq.KeepAlive = false;
rq.UserAgent = "User-Agent=Mozilla/5.0 Firefox/1.0.7";
rq.Proxy = null;
rq.ContentType = "application/www-form-urlencoded";
rq.ProtocolVersion = HttpVersion.Version10;
rq.ClientCertificates.Add(X509Certificate.CreateFromCertFile(chain_file));
rq.ClientCertificates.Add(new X509Certificate2(pem_file));
//rq.ClientCertificates.Add(X509Certificate.CreateFromCertFile(key_file)); ????
string dataToSend = String.Format("my data");
byte[] byteArray = Encoding.UTF8.GetBytes(dataToSend);
rq.ContentLength = byteArray.Length;
Stream dataStream = rq.GetRequestStream();
Answer the question
In order to leave comments, you need to log in
Maybe this will solve the problem: curl.haxx.se/mail/archive-2008-07/0038.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question