คำขอ Curl SSL 400 คำขอไม่ถูกต้อง

ฉันกำลังพยายามส่งคำขอโดยใช้ php และ curl นี่คือตัวอย่างการทำงานที่ฉันใช้จากบรรทัดคำสั่ง

curl -k --cacert c:/cert/server_ca.pem  --cert c:/cert/signed_client_cert.pem --key c:/cert/cert_req_rsa_private_key.pem 

นี่คือสิ่งที่ฉันมีจนถึงตอนนี้ มันส่งคืนคำขอที่ไม่ถูกต้อง 400- มีใครรู้ว่าฉันจะได้รับข้อผิดพลาดที่เป็นประโยชน์มากขึ้นได้อย่างไร หรือสิ่งที่ฉันอาจทำผิด?

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);

person kevinn2065    schedule 21.08.2014    source แหล่งที่มา


คำตอบ (2)


คำสั่ง curl ไม่สมบูรณ์ ดังนั้นจึงยากที่จะบอกว่าอะไรจะแตกต่าง (หรืออาจจะไม่) แตกต่างออกไป แต่จากบรรทัดคำสั่ง Curl ใช้ Accept: */*; และไม่ได้ใช้ Content-Type (ดูการจับภาพ Wireshark ด้านล่างสำหรับ curl www.google.com))

สำหรับการอ่านความแตกต่างระหว่าง Accept และ Content-Type โปรดดูที่ https://webmasters.stackexchange.com/questions/31212/difference-between-accept-and-content-type-http-headersบน Webmasters Stack Exchange

ป้อนคำอธิบายรูปภาพที่นี่


แค่การหลุดของจักรยาน แต่ยังมีสิ่งที่ต้องปรับปรุง:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

หากคุณรู้สึกว่าต้องใช้มันเช่นนั้น ให้เลือกโปรโตคอลที่ไม่เปิดเผยตัวตน จะช่วยเซิร์ฟเวอร์ไม่ให้ส่งใบรับรองเนื่องจากไม่มีการตรวจสอบใดๆ เลย

person jww    schedule 22.08.2014

น่าแปลกที่ดูเหมือนว่าปัญหาจะเป็นข้อบกพร่องใน Curl ของ Php ฉันเปลี่ยนมาใช้ httprequest และมันก็ใช้งานได้

person kevinn2065    schedule 29.08.2014