Reputation: 329
can you please help me with this issue.
I need to connect to json API and authenticate (connectorauth) via two parameters - key and connector_id. Key is the API key, and connector_id is just an id. I also have a url to extract the data from.
All I know is that I have to get the data via post and curl. Can you please send me an example script to authenticate. I'm not sure how to use the two parameters key and connector_id.
Should I use them in header, or I should use CURLOPT_USERPWD.
On success, I should get this result -
Thanks
Upvotes: 2
Views: 1068
Reputation: 300
Try this,
$url
will be the post url
$params
is query string for eg:- key=somevalue&connector_id=value
$count
no of parameters passed. Int this example 2 key and connector_id
function download_page($url, $count, $params) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_POST, $count);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
Upvotes: 2