PHP I use Curl crawl page, local debugging can be, but put on the server to appear 400badrequest

Source: Internet
Author: User
Tags openssl library
 !--? php$htmlstr = get_html ("Https://api.weibo.com/oauth2/access_ token?client_id=1233847790&client_secret=c8ba38aa75acc3830fff1eeeb1538723&grant_type=authorization_code& redirect_uri=http://www.yuecong.top&code=55b811f959d2afb495056e7e73f5ba5b "), echo $htmlstr; function get_html ($url    ) {$ch = Curl_init ();    curl_setopt ($ch, curlopt_followlocation, true);    curl_setopt ($ch, Curlopt_url, $url);    curl_setopt ($ch, curlopt_timeout,120); curl_setopt ($ch, Curlopt_useragent, "mozilla/5.0 (Windows NT 6.1;    WOW64) applewebkit/535.1 (khtml, like Gecko) chrome/14.0.835.202 safari/535.1 "); curl_setopt ($ch, Curlopt_returntransfer, 1);//302redirect curl_setopt ($ch, Curlopt_post, true);//use POST mode Curl_ Setopt ($ch, Curlopt_header, false); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_ssl_    Verifypeer, false);//Trust HTTPS Certificate $content = curl_exec ($ch);    Curl_close ($ch); return $content;} ?-->

I use localhost on my own computer to access the normal return value, but placed on the server and then go to the browser to display the 400badrequest

Reply content:

 !--? php$htmlstr = get_html ("Https://api.weibo.com/oauth2/access_ token?client_id=1233847790&client_secret=c8ba38aa75acc3830fff1eeeb1538723&grant_type=authorization_code& redirect_uri=http://www.yuecong.top&code=55b811f959d2afb495056e7e73f5ba5b "), echo $htmlstr; function get_html ($url    ) {$ch = Curl_init ();    curl_setopt ($ch, curlopt_followlocation, true);    curl_setopt ($ch, Curlopt_url, $url);    curl_setopt ($ch, curlopt_timeout,120); curl_setopt ($ch, Curlopt_useragent, "mozilla/5.0 (Windows NT 6.1;    WOW64) applewebkit/535.1 (khtml, like Gecko) chrome/14.0.835.202 safari/535.1 "); curl_setopt ($ch, Curlopt_returntransfer, 1);//302redirect curl_setopt ($ch, Curlopt_post, true);//use POST mode Curl_ Setopt ($ch, Curlopt_header, false); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_ssl_    Verifypeer, false);//Trust HTTPS Certificate $content = curl_exec ($ch);    Curl_close ($ch); return $content;} ?-->

I use localhost on my own computer to access the normal return value, but placed on the server and then go to the browser to display the 400badrequest

First Test a non-HTTPS link, such as a random URL (http://www.baidu.com), to see if you can get the content, if you can then test the https://www.baidu.com, at this time if there is a bad request. So the question should be the version of PHP that appears. Our system has encountered a similar problem, PHP upgrade from 5.2.27 to 5.3.35 this situation, non-HTTP normal, HTTPS problems. The problem is probably due to a conflict between PHP and the OpenSSL library. Our environment is CentOS.

Curlopt_ssl_verifypeer in the code should not be true?

URL there is no string stitching to see if there is a line break or something

  • 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.