Skip to content

Instantly share code, notes, and snippets.

@johnnygoodman
Created October 2, 2011 21:13
Show Gist options
  • Save johnnygoodman/1257965 to your computer and use it in GitHub Desktop.
Save johnnygoodman/1257965 to your computer and use it in GitHub Desktop.
PHP Curl Send POST request
<?php
/**
* Send a POST requst using cURL
* @param string $url to request
* @param array $post values to send
* @param array $options for cURL
* @return string
*/
function curl_post($url, array $post = NULL, array $options = array())
{
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 4,
CURLOPT_POSTFIELDS => http_build_query($post)
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}
?>
@almustafago
Copy link

So how do I go sending multiple invoice in HTTP post something like this

{
"funcrr":"create_insert_new_delivery",
"data":{
"name":"James",
"email":"james@someone.com",

//MORE OF LIKE AN ARRAY BUT IN HTTP FORM
"product_name":"Pear",
"product_weight":"30",
"product_name":"Rice",
"product_weight":"60",
"product_name":"Yoghury",
"product_weight":"100",
.................................................
"product_name":" n..,
"product_weight":" n,
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment