Ask a phpcurl post submission question

Source: Internet
Author: User
Ask a question about POST submission of PHPCURL. I encountered a problem when I learned about the sendCloud platform of Sohu in the past two days.

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


The official documents are as follows:
* Request interface (post request is recommended. do not use multipart-post):/list. create * parameter description: Required parameter type description api_user string is the request SC authentication account api_key string is the request SC authentication password addres sstring is the list alias address for example: developers@sendcloud.org or Developersname string is list name cannot be greater than 16 Chinese characters description string no list description cannot be greater than 85 Chinese characters


Therefore, I entered the following 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. an email list is created.

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


However, a problem occurs when submitting with php curl. the code is as follows:
 '*', 'Api _ key' => '*', 'address' => 'runnerlee @ maillist.sendcloud.org ', 'name' => 'test Mail list created by Abao ', 'description' => 'this is the test email list created by Abao',); 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 );

At this time, bad username/password is always returned. if you open the interface url directly in the browser, it is also a reality of bad username/password.
So I guess the data is not submitted.

Baidu said setting curl_setopt ($ ch, CURLOPT_VERIFYHOST, true), but I reported an error when setting
Notice: curl_setopt(): CURLOPT_SSL_VERIFYHOST no longer accepts the value 1, value 2 will be used instead in F:\www\sendCloud\demo.php on line 13


Even more strange is that, using the same code, you can call/mail. send. json, that is, the interface for sending emails, but submit the email normally.

Thank you very much for your help!


Reply to discussion (solution)

Output curl_error () and curl_errno to see?

Your form gets
{"Message": "error", "errors": ["Bad username/password! "]}

Your php code gets
Array (2) {["message"] => string (5) "error" ["errors"] => array (1) {[0] => string (24) "Bad username/password! "}}

If you do not provide the correct username and password, you cannot get the correct result.

Your form gets
{"Message": "error", "errors": ["Bad username/password! "]}

Your php code gets
Array (2) {["message"] => string (5) "error" ["errors"] => array (1) {[0] => string (24) "Bad username/password! "}}

If you do not provide the correct username and password, you cannot get the correct result.



The username and password are correct, but they are coded when they are sent out.

The cause is found. when $ data is an array, content-type is automatically converted to multipart/form-data, but this interface does not accept multipart/form-data, this problem occurs.

Thank you!

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.