: This article describes how to use PHP curl extension to submit json-format data. For more information about PHP tutorials, see. Instance code
$ch = curl_init();curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER=>true, CURLOPT_POST=>true, CURLOPT_HEADER=>false, CURLOPT_TIMEOUT=>30, CURLOPT_HTTPHEADER=>["Content-type:application/json"], CURLOPT_URL=>"http://localhost/city", CURLOPT_POSTFIELDS=>'{"province_id":39}', ]);$result = curl_exec($ch);print_r($result);
Returned results:
{"Code": 1, "data": [{"id": "40", "name": "Shijiazhuang City" },{ "id": "64 ", "name": "Tangshan city" },{ "id": "80", "name": "Qinhuangdao City" },{ "id": "89", "name ": "Handan City" },{ "id": "110", "name": "Xingtai city" },{ "id": "131", "name ": "Baoding city" },{ "id": "158", "name": "Zhangjiakou City" },{ "id": "177", "name ": "Chengde City" },{ "id": "190", "name": "Cangzhou city" },{ "id": "208", "name ": "Langfang City" },{ "id": "220", "name": "Hengshui city"}]}
Note:
The default value of CURLOPT_HEADER is false. Therefore, you can leave this option unspecified.
If data in json format is not transmitted, use http_build_query to create the value of CURLOPT_POSTFIELDS (similar to name = tom & age = 25)
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above introduces the use of PHP curl extension to submit json format data, including content, hope to be helpful to friends interested in PHP tutorials.