问题
I want to send the following header using curl:
curl -H 'Authorization: OAuth oauth_signature_method="PLAINTEXT",⤦
⤥oauth_consumer_key="xxx",oauth_token="xxx",oauth_signature="xxx"' ⤦
⤥'https://external.ningapis.com/xn/rest/apiexample/1.0/Photo/recent⤦
⤥?xn_pretty=true&fields=image.url,title&count=2'
Above command is for command line usage. Anyone know how to execute this using PHP curl?
回答1:
The -H from curl command-line is CURLOPT_HTTPHEADER in PHP curl curl_setopt.
This should be the most basic example for what you need:
$auth = 'Authorization: YOUR_KEYS';
$url = 'https://external.ningapis.com/xn/rest/apiexample/1.0/Photo/recent?xn_pretty=true&fields=image.url,title&count=2';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($auth));
curl_exec($ch);
curl_close($ch);
来源:https://stackoverflow.com/questions/12071420/php-execute-curl-oauth