What are the problems with POST submission of a PHPCURL?

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: sendcloud. sohu. comwebapilist. create. json official documentation is as follows: * & nbsp; request interface (post request is recommended. do not use multipart-post): list. create * & ask a php curl post submission question
I encountered a problem when I learned about the sendCloud platform of Sohu over 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:
Parameter type description required
Api_user string is the account requesting SC authentication
Api_key string is the SC authentication password.
Addres sstring is a list of alias addresses such as [email protected] Developers
Name string indicates that the list name cannot contain more than 16 Chinese characters.
Description string no list description cannot contain more than 85 Chinese characters


Therefore, I entered the following in the command line:

curl -d "api_user=*&api_key=*&[email protected]&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:

Header ('content-Type: text/html; charset = utf-8 ');
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
Curl_setopt ($ ch, CURLOPT_URL, 'https: // sendcloud.sohu.com/webapi/list.create.json ');
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false );
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, false );
Curl_setopt ($ ch, CURLOPT_AUTOREFERER, 1 );
Curl_setopt ($ ch, CURLOPT_POST, 1 );
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
$ Data = array (
'Api _ user' => '*',
'Api _ key' => '*',
'Address' => [email protected] ',
'Name' => 'test email 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!


------ Solution ----------------------
Output curl_error () and curl_errno to see?
------ Solution ----------------------
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.

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.