How PHP uses Curl's Post method string and array-by-value differences

Source: Internet
Author: User
Recently in the work needs to request a third-party Java version of the interface, the first is to use an array for the parameter, after the code is written to find that the interface is not debugging, always hint that the argument is empty, tangled for a long time, decided to try to use the method of string to request the interface, did not expect this actually debugging success, This gives me an interest in studying the difference between the two.

The local test code is as follows:
curl.php


     functioncurl_post($url, $data){$ch= Curl_init (); curl_setopt ($ch, Curlopt_url,$url); curl_setopt ($ch, Curlopt_returntransfer,1); curl_setopt ($ch, Curlopt_post,1); curl_setopt ($ch, Curlopt_postfields,$data);$output= Curl_exec ($ch); Curl_close ($ch);return$output;}$params=Array();$params[' username '] =' Ben ';$params[' Password '] =' Lalala ';p Rint_r (Curl_post (' http://localhost/curl/post.php ',$params));$params=Array();$params[' username '] = UrlEncode (' Ben ');$params[' Password '] = UrlEncode (' Lalala ');$paramsStr="username={$params [' username ']}&password={$params [' Password ']}";p Rint_r (Curl_post (' http://localhost/curl/post.php ',$paramsStr));?>

post.php


   
    echo"-------php://input-----
";var_dump(@file_get_contents('php://input'));echo"-------post-----
";var_dump($_POST);echo"-------server-----
";var_dump($_SERVER);

The execution results can be referred to as follows:

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    Copyright NOTICE: This article for Bo Master original article, reprint please indicate the source and author name, respect others also respect oneself

    The above describes the PHP using Curl Post method string and the difference in the value of the array, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • Related Article

    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.