PHP Curl Curlopt_postfields using arrays and string differences

Source: Internet
Author: User
We use these two variables to do the Curl post test separately:


   
    // 数组$arr_data = ['a' => 'apple'];// 字符串$str_data = '{"a":"apple"}';

Then the following is the result of printing from the server side:

The above diagram parses the CURLOPT_POSTFIELDS difference between using an array and a string, respectively, from $ _server[' Content_Type ', $ _post variable, and php://input.

Finally, we can conclude that:
1) when using the array

    • HTTP request Header Content-type will be set to Multipart/form-data;
    • The contents of the array can be obtained from $_post;
    • Using File_get_content ("Php://input") is empty, and for this, the PHP manual also says:

      Php://input isn't available with enctype= "Multipart/form-data"


2) when using a string
    • HTTP request Header Content-type will be set to application/x-www-form-urlencoded;
    • The string content becomes the key of an element inside the $_post;
    • The string contents can be obtained from the php://input completely;

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the PHP curl Curlopt_postfields the use of arrays and string differences, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • 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.