Ask a PHP curl for post submission problems

Source: Internet
Author: User
These two days in the study of Sohu Sendcloud platform, encountered a problem.

There is an interface:
Https://sendcloud.sohu.com/webapi/list.create.json


The official documentation is this:
* Request interface (recommended to use POST request, note do not use Multipart-post):/list.create* parameter Description: Whether the parameter  type  must  describe the  api_user  string  is  request SC authentication account Api_key  string  is  request  SC authentication password addres  sstring  is the  list alias address  For example: developers@sendcloud.org or Developersname  string  is a  list name  cannot be greater than 16 Chinese characters description  A string no  list description  cannot be greater than 85 Chinese characters


So, I typed this in the command line:
Curl-d "api_user=*&api_key=*&address=runnerleer@maillist.sendcloud.org&name=demo&description= This is a demo list "Https://sendcloud.sohu.com/webapi/list.create.json

The submission is correct and a mailing list is created.

Try to construct a form submission, and also submit the correct
    


However, with PHP curl submission, there is a problem, the code is as follows:
 
  ' * ', ' api_key ' = ' * ', ' address ' = ' runnerlee@maillist.sendcloud.org ', ' name ' = ' abao ' new test mailing list ', ' Description ' = ' This is Abao new test mailing list ', curl_setopt ($ch, Curlopt_postfields, $data); curl_setopt ($ch, Curlopt_ Postfields, $data); if (false = = = $result =curl_exec ($ch)) {echo ' false:
';} Var_dump (Json_decode ($result, True)); Curl_close ($ch);

This time always returns bad Username/password, if the URL that opens the interface directly in the browser is also the real bad username/password.
So I guess the data didn't go up.

Baidu said set curl_setopt ($ch, curlopt_verifyhost,true), but I set an error
Notice:curl_setopt (): Curlopt_ssl_verifyhost no longer accepts the value 1, value 2 would be used instead in F:\www\sendCl oud\demo.php on line 13


It is even more strange to use the same code, call/mail.send.json that is the interface to send mail, but can be submitted normally.

Please help to see, thank you very much!


Reply to discussion (solution)

Output Curl_error () and Curl_errno look?

Your form is getting
{"Message": "Error", "Errors": ["Bad username/password!"]}

Your PHP code gets
Array (2) {["Message"]=> string (5) "Error" ["Errors"]=> Array (1) {[0]=> string ("Bad username/password!"} }

You don't give the correct username and password, and you don't get the right results.

Your form is getting
{"Message": "Error", "Errors": ["Bad username/password!"]}

Your PHP code gets
Array (2) {["Message"]=> string (5) "Error" ["Errors"]=> Array (1) {[0]=> string ("Bad username/password!"} }

You don't give the correct username and password, and you don't get the right results.



User name and password is correct, just send out the time to play the code ha.

The problem has been found, $data an array, Content-type automatically to Multipart/form-data, but this interface does not accept multipart/form-data, the problem arises.

Thanks two bit!
  • 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.