Copy CodeThe code is as follows:
function Do_post_request ($url, $data, $optional _headers = null)
{
$params = Array (' http ' = = Array (
' Method ' = ' POST ',
' Content ' = $data
));
if ($optional _headers!== null) {
$params [' http '] [' header '] = $optional _headers;
}
$ctx = Stream_context_create ($params);
$fp = @fopen ($url, ' RB ', false, $ctx);
if (! $fp) {
throw new Exception ("Problem with $url, $php _errormsg");
}
$response = @stream_get_contents ($FP);
if ($response = = = False) {
throw new Exception ("Problem reading data from $url, $php _errormsg");
}
return $response;
}
Use the following:
Copy the Code code as follows:
JSON string
$data = "{...}";
Convert an array
$data =json_decode ($data, true);
$postdata = Http_build_query ($data);
Do_post_request ("http://localhost", $postdata);
http://www.bkjia.com/PHPjc/736791.html www.bkjia.com true http://www.bkjia.com/PHPjc/736791.html techarticle Copy the code code as follows: function Do_post_request ($url, $data, $optional _headers = null) {$params = array (' http ' = Array (' method ') = ' POST ', ' content ' = $data)); if ($optional _ ...