Submit json format data using PHP curl extension

Source: Internet
Author: User
: 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.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.