: This article mainly introduces the example of using curl for post requests in php. if you are interested in the PHP Tutorial, refer to it. In work, you need to use the curl POST request to obtain data from a third-party server. The following is the php version implementation code for memo.
"Find_wonder"); $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data); curl_setopt ($ ch, batch, 1); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ ch, CURLOPT_AUTOREFERER, 1); curl_setopt ($ ch, CURLOPT_MAXREDIRS, 4); curl_setopt ($ ch, CURLOPT_ENCODING, ""); // you must decompress it to prevent garbled curl_setopt ($ ch, CURLOPT _ USERAGENT, "Mozilla/5.0 (Windows NT 5.1; zh-CN) AppleWebKit/535.12 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/535.12"); curl_setopt ($ ch, CURLOPT_TIMEOUT, 15); $ output = curl_exec ($ ch); curl_close ($ ch); print_r ($ output);?>
Note that the data returned by hao.qq.com is sent by gzip and chunk. you must enable the automatic decompression function of curl to obtain the extracted data. otherwise, garbled characters may occur.
Record the above source code file as curl_post.php and execute it on the command line.
Php curl_post.php
The following is an example of the obtained result.
The above example is to send a POST request to hao.qq.com to obtain the specified code snippet. it is a mixture of p and script code snippets and will generate a page effect similar to the following:
The above describes the use of curl in php for post request examples, including the content, hope to be helpful to friends interested in PHP tutorials.