note 116696 added to book.curl
| From: | m dot rizwan_47 at yahoo dot com | Date: | Thu, 12 Feb 2015 15:11:15 +0000 |
| Subject: | note 116696 added to book.curl | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201707@lists.php.net to get a copy of this message | ||
function make_curl_request($endpoint, $params=array(), $type){
if($type=='POST' or $type=='JSON'){
$url = $endpoint;
}else{
$url = $endpoint.'?'.http_build_query($params);
}
$curl = curl_init();
$opts = array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url,
CURLOPT_USERAGENT => 'Codular Sample cURL Request',
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0
);
if($type=='POST' or $type=='JSON'){
if($type=='JSON'){
$opts[CURLOPT_POSTFIELDS] = json_encode($params);
$opts[CURLOPT_HTTPHEADER] = array(
'Content-Type: application/json',
'Content-Length: ' . strlen(json_encode($params))
);
}else{
$opts[CURLOPT_POSTFIELDS] = $params;
}
$opts[CURLOPT_POST] = 1;
}
curl_setopt_array($curl, $opts);
$resp = curl_exec($curl);
curl_close($curl);
return $resp;
}
For making JSON requests too
----
Server IP: 72.52.91.14
Probable Submitter: 39.63.58.45
----
Manual Page -- http://php.net/manual/en/book.curl.php
Edit -- https://master.php.net/note/edit/116696
Del: integrated -- https://master.php.net/note/delete/116696/integrated
Del: useless -- https://master.php.net/note/delete/116696/useless
Del: bad code -- https://master.php.net/note/delete/116696/bad+code
Del: spam -- https://master.php.net/note/delete/116696/spam
Del: non-english -- https://master.php.net/note/delete/116696/non-english
Del: in docs -- https://master.php.net/note/delete/116696/in+docs
Del: other reasons-- https://master.php.net/note/delete/116696
Reject -- https://master.php.net/note/reject/116696
Search -- https://master.php.net/manage/user-notes.php