Ask a PHP curl for post submission encounters with related issues

Source: Internet
Author: User
Ask a PHP curl for post submission problems
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 (we recommend using a POST request, be careful not to use Multipart-post):
/list.create
* Parameter Description:
Whether the parameter type must describe the description
Api_user string is a request for SC Certified account
Api_key string is a request for SC authentication password
Addres sstring is the list address for example: [email protected] Developers
Name string is a list name cannot be greater than 16 Chinese characters
Description 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=*&[email Protected]&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:

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 ' = ' Abao new test mailing list ',
' Description ' = ' This is the 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!


------to solve the idea----------------------
Output Curl_error () and Curl_errno look?
------to solve the idea----------------------
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.
  • 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.