trying to do the equivalent of this in PHP - and failing :):
curl -H "X-abc-AUTH: 123456789" http://APIserviceProvider=http://www.cnn.com;
"123456789" is the API key. The command line statement works fine.
PHP code (does not work):
$urlToGet = "http://www.cnn.com";
$service_url = "http://APIserviceProvider=$urlToGet";
//header
$contentType = 'text/xml'; //probably not needed
$method = 'POST'; //probably not needed
$auth = 'X-abc-AUTH: 123456789'; //API Key
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $service_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
//does not work
// curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Content-type: ' .
// $contentType . '; auth=' . $auth));
//works! (THANKS #Fratyr for the clue):
curl_setopt($ch, CURLOPT_HTTPHEADER, Array($auth));
//this works too (THANKS #sergiocruz):
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Some_custom_header: 0',
'Another_custom_header: 143444,12'
));
//exec
$data = curl_exec($ch);
echo $data;
curl_close($ch);
Any ideas?
In order to get custom headers into your curl you should do something like the following:
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Some_custom_header: 0',
'Another_custom_header: 143444,12'
));
Therefore the following should work in your case (given X-abc-AUTH is the only header you need to send over):
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-abc-AUTH: 123456789' // you can replace this with your $auth variable
));
If you need additional custom headers, all you have to do is add on to the array within the curl_setopt.
I hope this helps :)
Use the following Syntax
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.example.com/process.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = 'X-abc-AUTH: 123456789';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
$headers[] = 'Accept-Encoding: gzip, deflate';
$headers[] = 'Accept-Language: en-US,en;q=0.5';
$headers[] = 'Cache-Control: no-cache';
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=utf-8';
$headers[] = 'Host: 202.71.152.126';
$headers[] = 'Referer: http://www.example.com/index.php'; //Your referrer address
$headers[] = 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0';
$headers[] = 'X-MicrosoftAjax: Delta=true';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
curl_close ($ch);
print $server_output ;
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'auth=' . $auth
));
You set only one request header, not the two you wanted. You could do it for example like this:
// input
$urlToGet = "http://www.cnn.com";
// url
$service_url = sprintf("http://APIserviceProvider=%s", urlencode($urlToGet));
//header
$contentType = 'Content-type: text/xml'; //probably not needed
$auth = 'X-abc-AUTH: 123456789'; //API Key
$method = 'POST'; //probably not needed
// curl init
$ch = curl_init($service_url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLINFO_HEADER_OUT => true,
CURLOPT_HTTPHEADER => [
$contentType,
$auth,
],
]);
// curl exec
$data = curl_exec($ch);
curl_close($ch);
// output
echo $data;
(change the service url to the right one to get this to work)
Related
I need to track a tracking number in this tracking website. However, the form is in iFrame div, how do I POST request using CURL in PHP? Below is my code.
iFrame src:
https://home.abxexpress.com.my/track_multiple.html
Original src:
https://abxexpress.com.my/Home/Tracking
Controller:
public function track($trackingID)
{
$data = array(
'tairbillno' => $trackingID
);
print_r($data);
$url = file_get_contents('https://home.abxexpress.com.my/track_multiple.html');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
curl_close($curl);
echo $result;
}
Sample of tracking number:
99951513362
you can use this php-curl Code to send a simple post request to callback-page to get tracking info in html format,
after you can print content direct in your website(its work correctly,with the original style ), also you can use this content to extract all info you want , by any DOM extract librery like : php DOMDocument
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://home.abxexpress.com.my/track_multipleResult.asp?vsearch=True');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "tairbillno=99951513362");//replace number your traking number
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Connection: keep-alive';
$headers[] = 'Pragma: no-cache';
$headers[] = 'Cache-Control: no-cache';
$headers[] = 'Upgrade-Insecure-Requests: 1';
$headers[] = 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36';
$headers[] = 'Origin: https://home.abxexpress.com.my';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9';
$headers[] = 'Sec-Fetch-Site: same-origin';
$headers[] = 'Sec-Fetch-Mode: navigate';
$headers[] = 'Sec-Fetch-User: ?1';
$headers[] = 'Sec-Fetch-Dest: document';
$headers[] = 'Referer: https://home.abxexpress.com.my/track_multiple.html';
$headers[] = 'Accept-Language: it,it-IT;q=0.9,en-US;q=0.8,en;q=0.7,ar;q=0.6';
$headers[] = 'Cookie: ASPSESSIONIDAWDDSADQ=LLOJGMICLOOKHGEHJHPBMBKE';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
I'm wondering if/how you can add custom headers to a cURL HTTP request in PHP. I'm trying to emulate how iTunes grabs artwork and it uses these non-standard headers:
X-Apple-Tz: 0
X-Apple-Store-Front: 143444,12
How could I add these headers to a request?
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-Apple-Tz: 0',
'X-Apple-Store-Front: 143444,12'
]);
https://www.php.net/manual/en/function.curl-setopt.php
Use the following Syntax
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.example.com/process.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
'X-Apple-Tz: 0',
'X-Apple-Store-Front: 143444,12',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding: gzip, deflate',
'Accept-Language: en-US,en;q=0.5',
'Cache-Control: no-cache',
'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
'Host: www.example.com',
'Referer: http://www.example.com/index.php', //Your referrer address
'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0',
'X-MicrosoftAjax: Delta=true'
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
curl_close ($ch);
print $server_output ;
$subscription_key = '';
$host = '';
$request_headers = [
'X-Mashape-Key:' . $subscription_key,
'X-Mashape-Host:' . $host
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
$season_data = curl_exec($ch);
if (curl_errno($ch)) {
print "Error: " . curl_error($ch);
exit();
}
// Show me the result
curl_close($ch);
$json = json_decode($season_data, true);
Here is one basic function:
/**
*
* #param string $url
* #param string|array $post_fields
* #param array $headers
* #return type
*/
function cUrlGetData($url, $post_fields = null, $headers = null) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
if (!empty($post_fields)) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
}
if (!empty($headers))
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $data;
}
Usage example:
$url = "http://www.myurl.com";
$post_fields = 'postvars=val1&postvars2=val2';
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$dat = cUrlGetData($url, $post_fields, $headers);
I'm making code to run curl, but when I try to convert the code into a function on php, the code doesn't work.
I run the code in php xampp / cmd shell, PHP version 7, and I have also tried hosting, but the results are the same. I have tried adding data types like those found at https://www.w3schools.com/php/php_functions.asp, but it has no effect.
This is code without being included in the function:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://i.instagram.com/api/v1/friendships/create/2878405206/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "signed_body=cdb3985eb8de0d7ab8bf9a2282615e27452b3f71c30cc95d1b1a325d9f2e36d2.%7B%22_csrftoken%22%3A%221W9jdoDp4GkJRNvWwnZ9Mm1G5Tfh2ub1%22%2C%22user_id%22%3A%222878405206%22%2C%22radio_type%22%3A%22wifi-none%22%2C%22_uid%22%3A%2221423938509%22%2C%22device_id%22%3A%22android-0aaa681cf6d47fdb%22%2C%22_uuid%22%3A%22825ebac9-3235-4cad-b187-7ed685a06b37%22%7D&ig_sig_key_version=4");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'X-Ig-Connection-Type: WIFI';
$headers[] = 'User-Agent: Instagram 24.0.0.12.201 Android (4.4.4/19; 240dpi; 800x480; GT-I9060I; samsung; samsung; grandneove3g; in_ID)';
$headers[] = 'Accept-Language: id-ID, en-US';
$headers[] = 'Host: i.instagram.com';
$headers[] = 'X-Fb-Http-Engine: Liger';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$resultLast = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
print_r($resultLast);
and this is the code that has been used as a function:
function sendData($path,$dataHook){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataHook);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'X-Ig-Connection-Type: WIFI';
$headers[] = 'User-Agent: Instagram 24.0.0.12.201 Android (4.4.4/19; 240dpi; 800x480; GT-I9060I; samsung; samsung; grandneove3g; in_ID)';
$headers[] = 'Accept-Language: id-ID, en-US';
$headers[] = 'Host: i.instagram.com';
$headers[] = 'X-Fb-Http-Engine: Liger';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$resultLast = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $resultLast;
}
print_r(sendData('https://i.instagram.com/api/v1/friendships/create/2878405206','signed_body=cdb3985eb8de0d7ab8bf9a2282615e27452b3f71c30cc95d1b1a325d9f2e36d2.%7B%22_csrftoken%22%3A%221W9jdoDp4GkJRNvWwnZ9Mm1G5Tfh2ub1%22%2C%22user_id%22%3A%222878405206%22%2C%22radio_type%22%3A%22wifi-none%22%2C%22_uid%22%3A%2221423938509%22%2C%22device_id%22%3A%22android-0aaa681cf6d47fdb%22%2C%22_uuid%22%3A%22825ebac9-3235-4cad-b187-7ed685a06b37%22%7D&ig_sig_key_version=4'));
it should produce {"message": "login_required", "error_title": "You have logged out", "error_body": "Please log in again.", "logout_reason": 2, "status": "fail"}, but the function does not issue anything.
You forgot to add "/" at the end of the url
function sendData($path,$dataHook){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataHook);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'X-Ig-Connection-Type: WIFI';
$headers[] = 'User-Agent: Instagram 24.0.0.12.201 Android (4.4.4/19; 240dpi; 800x480; GT-I9060I; samsung; samsung; grandneove3g; in_ID)';
$headers[] = 'Accept-Language: id-ID, en-US';
$headers[] = 'Host: i.instagram.com';
$headers[] = 'X-Fb-Http-Engine: Liger';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$resultLast = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $resultLast;
}
print_r(sendData('https://i.instagram.com/api/v1/friendships/create/2878405206/','signed_body=cdb3985eb8de0d7ab8bf9a2282615e27452b3f71c30cc95d1b1a325d9f2e36d2.%7B%22_csrftoken%22%3A%221W9jdoDp4GkJRNvWwnZ9Mm1G5Tfh2ub1%22%2C%22user_id%22%3A%222878405206%22%2C%22radio_type%22%3A%22wifi-none%22%2C%22_uid%22%3A%2221423938509%22%2C%22device_id%22%3A%22android-0aaa681cf6d47fdb%22%2C%22_uuid%22%3A%22825ebac9-3235-4cad-b187-7ed685a06b37%22%7D&ig_sig_key_version=4'));
i try to Login to a API with the following Code
<?php
header('Content-type: application/json; charset=utf-8');
error_reporting(E_ALL);
ini_set('display_errors', '1');
$id = $_POST["id"];
$id2 = $_POST["id2"];
// URL to fetch
$url = "https://bpk.bs.picturemaxx.com/api/v1/user/login";
// Setting the HTTP Request Headers
$User_Agent = 'Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0';
$request_headers[] = 'X-picturemaxx-api-key: Key';
$request_headers[] = 'Content-Length:0';
$request_headers[] = 'Expect: ';
$request_headers[] = 'Authorization: Bearer token';
$username = "$id";
$password = "$id2";
$ch = curl_init($url);
// Set the url
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_USERAGENT, $User_Agent);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
// Execute
$result = curl_exec($ch); // Performs the Request, with specified
curl_setopt() options (if any).
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Closing
curl_close($ch);
?>
When i run this code all i get is "Request parameter 'password' is required". A example body to login from the API-Website looks like this
{
"password": "string",
"username": "string"
}
and a example CURL looks like this
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'X-picturemaxx-api-key: key' -d '{ \
"password": "pwd", \
"username": "usrname" \
}' 'https://bpk.bs.picturemaxx.com/api/v1/user/login'
How do I have to use the example body in PHP Curl to use the password so that the login works?
How can I continue to use the token created during login?
Thanks for solutions
I cannot see where are putting the username and password.
You have to add data to the cURL request.
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
Where $data is your array with username and password. And because the API is expecting json data, json_encode is used.
I was able to solve the problem. Here is my code if someone has similar difficulties
<?php
header('Content-type: text/html; charset=utf-8');
// URL to fetch
$url = "https://bpk.bs.picturemaxx.com/api/v1/user/login";
// Setting the HTTP Request Headers
$User_Agent = 'Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0';
$request_headers[] = 'X-picturemaxx-api-key: key';
$request_headers[] = 'Contect-Type:text/html';
$request_headers[] = 'Accept:text/html';
$request_headers[] = 'Accept: application/json';
$request_headers[] = 'Content-type: application/json';
$request_headers[] = 'Accept-Encoding: gzip, deflate, identity';
$request_headers[] = 'Expect: ';
$dataj = array (
'password' => 'passwd',
'username' => 'usrname',
);
$data_json = json_encode($dataj);
$request_headers[] = 'Content-Length: ' . strlen($data_json);
$ch = curl_init($url);
// Set the url
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_USERAGENT, $User_Agent);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING, "");
// Execute
$result = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Performs the Request, with specified curl_setopt() options (if any).
//$data = json_decode( file_get_contents( 'php://input' ), true );
// Closing
curl_close($ch);
$data = json_decode($result, true);
if ($code == 200) {
$result = json_decode($result, true);
print_r($result);
} else {
echo 'error ' . $code;
}
print_r($result);
print_r($data);
?>
With this spelling it works now.
$dataj = array (
'password' => 'passwd',
'username' => 'usrname',
);
Another mistake was that I used $data_json in the header before initializing it.
$data_json = json_encode($dataj);
$request_headers[] = 'Content-Length: ' . strlen($data_json);
I'm wondering if/how you can add custom headers to a cURL HTTP request in PHP. I'm trying to emulate how iTunes grabs artwork and it uses these non-standard headers:
X-Apple-Tz: 0
X-Apple-Store-Front: 143444,12
How could I add these headers to a request?
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-Apple-Tz: 0',
'X-Apple-Store-Front: 143444,12'
]);
https://www.php.net/manual/en/function.curl-setopt.php
Use the following Syntax
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.example.com/process.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
'X-Apple-Tz: 0',
'X-Apple-Store-Front: 143444,12',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding: gzip, deflate',
'Accept-Language: en-US,en;q=0.5',
'Cache-Control: no-cache',
'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
'Host: www.example.com',
'Referer: http://www.example.com/index.php', //Your referrer address
'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0',
'X-MicrosoftAjax: Delta=true'
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
curl_close ($ch);
print $server_output ;
$subscription_key = '';
$host = '';
$request_headers = [
'X-Mashape-Key:' . $subscription_key,
'X-Mashape-Host:' . $host
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
$season_data = curl_exec($ch);
if (curl_errno($ch)) {
print "Error: " . curl_error($ch);
exit();
}
// Show me the result
curl_close($ch);
$json = json_decode($season_data, true);
Here is one basic function:
/**
*
* #param string $url
* #param string|array $post_fields
* #param array $headers
* #return type
*/
function cUrlGetData($url, $post_fields = null, $headers = null) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
if (!empty($post_fields)) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
}
if (!empty($headers))
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $data;
}
Usage example:
$url = "http://www.myurl.com";
$post_fields = 'postvars=val1&postvars2=val2';
$headers = ['Content-Type: application/x-www-form-urlencoded'];
$dat = cUrlGetData($url, $post_fields, $headers);