As a third-party developer, you often need to call the platform interface. For remote calls, you need to use curl. the essence is that the method and parameters used are sent to the platform server in httppost mode. Simple Example: $ url; platform service address for calling the interface $ post_stringarray (AB); $ chcurl_init ();
As a third-party developer, you often need to call the platform interface. For remote calls, you need to use curl. The essence is to send the call method and parameters to the platform server through http post. Simple Example: $ url = 'HTTP: // '; // The Platform service address for calling the interface $ post_string = array ('A' =' B '); $ ch = curl_init ();
As a third-party developer, you often need to call the platform interface. For remote calls, you need to use curl. The essence is to send the call method and parameters to the platform server through http post.
Simple Example:
$ Url = 'HTTP: // '; // The Platform service address for calling the interface
$ Post_string = array ('A' => 'B ');
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_string );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, 10 );
Curl_setopt ($ ch, CURLOPT_TIMEOUT, 30 );
$ Result = curl_exec ($ ch );
Curl_close ($ ch );
In fact, the setting of CURLOPT_POSTFIELDS can also directly send arrays, but the consequence is that the request time is greatly increased, which takes about 2 seconds, for the same operation, the socket operation is normal in milliseconds.
If you use curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_string );
Changed to: curl_setopt ($ ch, CURLOPT_POSTFIELDS, http_build_query ($ post_data ));
The execution time returns to normal.
PS:
Http_build_query-Generate the request string after URL-encode
Description
StringHttp_build_query(Array $ formdata [, string $ numeric_prefix])
Generate a URL-encode request string using the given correlated (or subscript) array. ParametersFormdataIt can be an array or an object containing attributes. OneFormdataAn array can be a simple one-dimensional structure or an array composed of arrays (which can contain other arrays in turn ). If the numeric subscript is used in the basic arrayNumeric_prefixParameter. The value of this parameter is used as the prefix of the numeric subscript element in the base array. This is to allow PHP or other CGI programs to obtain valid variable names when decoding data later.
Note:
Use arg_separator.output to separate parameters.
Example #1 http_build_query () Example
$ Data = array ('foo' => 'bar ',
'Baz' => 'boom ',
'Cow' => 'milk ',
'Php' => 'hypertext processor'
);
Echo http_build_query ($ data); // foo = bar & baz = boom & cow = milk & php = hypertext + processor
?>
Example #2 http_build_query () use the following element of a number
$ Data = array ('foo', 'bar', 'baz', 'boom ', 'cow' => 'milk ', 'php' => 'hypertext processor ');
Echo http_build_query ($ data );
Echo http_build_query ($ data, 'myvar _');
?>