I'm trying to make a request using php and curl. Heres a working example that I use from command line
curl -k --cacert c:/cert/server_ca.pem --cert c:/cert/signed_client_cert.pem --key c:/cert/cert_req_rsa_private_key.pem
heres what I have so far, It returns a 400- bad request, does anyone know how I can get more usefull errors or what I could be doing wrong?
ini_set('display_errors',1);
//phpinfo();
$cert = "C:/cert/signed_client_cert.pem";
$key = "C:/cert/cert_req_rsa_private_key.pem";
$pass = "key1123";
$caInfo = "C:/cert/server_ca.pem";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.apitest.com/v/2/products/04003274058");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_CAINFO, $caInfo);
curl_setopt($ch, CURLOPT_SSLCERT, $cert);
curl_setopt($ch, CURLOPT_SSLKEY, $key);
curl_setopt($ch, CURLOPT_VERBOSE, true);
//curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $pass);
//curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');
//curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $pass);
//curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');
$response = curl_exec($ch);
echo curl_error($ch);
echo var_dump($response);
The curl
command is incomplete, so its hard to say what may (or may not) be different. But from the command line, Curl uses Accept: */*
; and does not use Content-Type
(see the Wireshark capture below for curl www.google.com
)).
For reading on the difference between Accept
and Content-Type
, see Difference between accept and content-type http headers on Webmasters Stack Exchange.
Just bike shedding, but this has room for improvement:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
If you feel you have to use it like that, then pick an anonymous protocol. It will save the server from sending its certificate since nothing is being verified anyway.
奇怪的是,这个问题似乎是Php卷曲的错误,我切换到了httprequest,它起作用了
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.