[英]How Can I Convert CURL command to PHP?
有人可以幫助我將以下curl命令轉換為PHP:
curl --key ~/Desktop/private.pem --cert ~/Desktop/cert.crt --header "Content-type: application/json; profile=http://example.com/docs/v1.0/schemas/list.json" https://example.com/sandbox/v1/list --data '{ "foo" : "bar" }'
我不確定如何通過PHP設置--key
和--cert
選項,以及如何獲取響應。
首先,這是您所追求的
<?php
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_URL, "https://example.com/sandbox/v1/list");
// Capture the output
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Set the key options
curl_setopt($ch, CURLOPT_SSLKEY, "~/Desktop/private.pem"); // Need to change to an absolute path
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, "password");
// Set the certificate options
curl_setopt($ch, CURLOPT_SSLCERT, "~/Desktop/cert.crt"); // Need to change to absolute path
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "password");
// Set the headers
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/json; profile=http://example.com/docs/v1.0/schemas/list.json"));
//Set the data
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{ "foo" : "bar" }');
// Run the request
$result=curl_exec($ch);
curl_close($ch);
在此處查看有關cURL的手冊頁
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.