how to pass JSON via curl with php

function jsoncurl($url, $fieldString){
	//open connection
	$options = array(
		CURLOPT_RETURNTRANSFER => true, // return web page
		CURLOPT_FOLLOWLOCATION => true, // follow redirects
		CURLOPT_USERAGENT => "spider", // who am i
		CURLOPT_AUTOREFERER => true, // set referer on redirect
		CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
		CURLOPT_TIMEOUT => 120, // timeout on response
		CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
	$ch = curl_init();

	//set the url, number of POST vars, POST data

	//for some diff
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
	curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $json );
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt_array( $ch, $options );
	//execute post
	$result = curl_exec($ch); 
	$header = curl_getinfo( $ch );

	//close connection
	return $result;

$result=jsoncurl($url, $fieldString);

Ref :


About rahul23134654

Hi, I am Rahul Meha , B.E. in (I.T.)
This entry was posted in PHP. Bookmark the permalink.

One Response to how to pass JSON via curl with php

  1. Pingback: Lazuli » [PHP] POSTメソッドでJSONを送る処理について

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s