Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl posting with header application/x-www-form-urlencoded

$post_data="dispnumber=567567567&extension=6"; $url="http://xxxxxxxx.xxx/xx/xx"; 

I need to post this $post_data using cURL php with header application/x-www-form-urlencoded i am new for curl any one help this out.

like image 469
Saravanan M P Avatar asked Sep 20 '13 09:09

Saravanan M P


People also ask

How do you curl using application X www form Urlencoded?

To post a web form with Curl, you need to use the -d command line option and pass the form data as key/value pairs. By default, Curl sends an HTTP POST request and posts the provided form data with the application/x-www-form-urlencoded content type.


2 Answers

<?php // // A very simple PHP example that sends a HTTP POST to a remote site //  $ch = curl_init();  curl_setopt($ch, CURLOPT_URL,"http://xxxxxxxx.xxx/xx/xx"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,             "dispnumber=567567567&extension=6"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));   // receive server response ... curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  $server_output = curl_exec ($ch);  curl_close ($ch);  // further processing .... if ($server_output == "OK") { ... } else { ... }  ?> 
like image 104
Shakti Patel Avatar answered Oct 09 '22 03:10

Shakti Patel


 $curl = curl_init();  curl_setopt_array($curl, array(             CURLOPT_URL => "http://example.com",             CURLOPT_RETURNTRANSFER => true,             CURLOPT_ENCODING => "",             CURLOPT_MAXREDIRS => 10,             CURLOPT_TIMEOUT => 30,             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,             CURLOPT_CUSTOMREQUEST => "POST",             CURLOPT_POSTFIELDS => "value1=111&value2=222",             CURLOPT_HTTPHEADER => array(                 "cache-control: no-cache",                 "content-type: application/x-www-form-urlencoded"             ),         ));  $response = curl_exec($curl);  $err = curl_error($curl);   curl_close($curl);   if (!$err)  {       var_dump($response);  } 
like image 30
GeekHare Avatar answered Oct 09 '22 04:10

GeekHare