Posted inProgramming / Mysql / Mysqli / php

cURL POST header parameters file json request

cURL POST header parameters file json request

In this Post We Will Explain About is cURL POST header parameters file json request With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to What is cURL withExample

In this post we will show you Best way to implement how to POST Form Data and file with cURL with Example, hear for What is the cURL command-line syntax to do a POST request?with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Example

cURL POST header parameters file json request step 1
cURL POST header parameters file json request step 1

Steps to use cURL
step : 1curl_init
step : 2curl_setopt
step : 3curl_exec
step : 4curl_close

Here we will fine Easy cURL example.

 function getCurlData($url, $simple_post_param = false)
{
   // check simple if cURL easy way installed or not in wer system? 
	if (!function_exists('curl_init')){
		return 'Sorry your cURL is not installed!,Now';
	}
	//simple curl_init
	$ch = curl_init();
	
	//pass simple url
	curl_setopt($ch, CURLOPT_URL, $url);
	//simple CURLOPT_RETURNTRANSFER 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
	if ($simple_post_param)
	{
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $simple_post_param);
	}
	
	//check url ssl domain or not
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	
	//supproted browser
	curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 ;Windows NT 6.1; WOW64; AppleWebKit/537.36 ;KHTML, like Gecko; Chrome/39.0.2171.95 Safari/537.36");
	//simple example execute
	$contents = curl_exec($ch);
	//get informaion
	$headers = curl_getinfo($ch);
	// close curl
	curl_close($ch);
	
	// all results return
	return array($contents, $headers);
}

Use curl -X POST and add -F for every all the parameters which we want to simple add to the POST.

    curl -X POST -F 'firstparam=value1' -F 'secondparam=value2' http://wer-domain.com/page.php

Output which we will get :

 
     Array(
      'firstparam' => 'value1',
      'secondparam' => 'value2'
    )

Example

I hope you have Got What is how to POST Form Data and file with cURL with Example And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

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

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype