Answers for "curl method for php"

PHP
2

CURL PHP POST

<?php

$post = [
    'username' => 'user1',
    'password' => 'passuser1',
    'gender'   => 1,
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.domain.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$response = curl_exec($ch);
var_export($response);
Posted by: Guest on March-26-2021
8

php curl post

// set post fields
$post = [
    'username' => 'user1',
    'password' => 'passuser1',
    'gender'   => 1,
];

$ch = curl_init('http://www.example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

// execute!
$response = curl_exec($ch);

// close the connection, release resources used
curl_close($ch);

// do anything you want with your response
var_dump($response);
Posted by: Guest on May-15-2020
2

php curl

// The ultimate function for all php curl requests all in one
function curl( $api_url,$request = 'get' , $params = array() , $mode = false , $timeout='')
{
    $request = strtolower($request);

    $ch = curl_init($api_url);

    if($request == 'post')
    {
        curl_setopt ($ch, CURLOPT_POST, TRUE);
        curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($params));
    }
    
    if( $timeout != ''  )
    {
        curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
    }

    if($request == 'put')
    {
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    }
  
    if($request == 'delete')
    {
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    }

    curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

    $response     = curl_exec($ch);

    if($mode)
        $response     = json_decode($response , $mode);
    else
        $response     = json_decode($response);    

    return $response;
}
Posted by: Guest on July-03-2021
0

curl php

// Initialize Curl 
 $curl = curl_init();
 curl_setopt($curl, CURLOPT_URL, "https://coinmarketcap.com/"); // set live website where data from
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); // default
 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // default
 $content = curl_exec($curl);

 preg_match_all('!<p color="text3" class="sc-AxhUy bzeXdk coin-item-symbol" font-size="1">(.*?)</p>!', $content, $matches);

 var_dump($matches);
Posted by: Guest on March-05-2021
0

curl php example

function callAPI($method, $url, $data){
   $curl = curl_init();
   switch ($method){
      case "POST":
         curl_setopt($curl, CURLOPT_POST, 1);
         if ($data)
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
         break;
      case "PUT":
         curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
         if ($data)
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);			 					
         break;
      default:
         if ($data)
            $url = sprintf("%s?%s", $url, http_build_query($data));
   }
   // OPTIONS:
   curl_setopt($curl, CURLOPT_URL, $url);
   curl_setopt($curl, CURLOPT_HTTPHEADER, array(
      'APIKEY: 111111111111111111111',
      'Content-Type: application/json',
   ));
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
   // EXECUTE:
   $result = curl_exec($curl);
   if(!$result){die("Connection Failure");}
   curl_close($curl);
   return $result;
}
Posted by: Guest on October-15-2020
-2

curl php get method

$get_data = callAPI('GET', 'https://api.example.com/get_url/'.$user['User']['customer_id'], false);
$response = json_decode($get_data, true);
$errors = $response['response']['errors'];
$data = $response['response']['data'][0];
Posted by: Guest on October-15-2020

Browse Popular Code Answers by Language