nguyenminh

curl post data example

A very simple PHP example that sends a HTTP POST to a remote site

$url='https://nguyenminh.me';
$postData = array('name'=> 'key', 'value'=>'f4a742dcd9b92e79' , 'id'=>999);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
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');
$response = curl_exec($ch);
  var_dump($response);
curl_close($ch);
exit;


<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://ips.congdanit.com/kiemtracapnhat");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"p1=3.0.0&p2=z78&p3=1");
// in real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS, 
//          http_build_query(array('postvar1' => 'value1')));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
var_dump($server_output);
 // further processing ....
//if ($server_output == "OK") { ... } else { ... }

?>

Categorised in: Tổng hợp

0 Comments for "curl post data example"

One thought on “curl post data example”

  1. admin says:

    Get example
    $url=’http://localhost:8689/’;
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    $result = curl_exec($curl);
    curl_close($curl);
    dd($result);

Leave a Reply

Your email address will not be published. Required fields are marked *