PHP Curl does not get data to help me see why

Source: Internet
Author: User

http://fuzhou.8684.cn/



My code is like this.

 ' */* ', ' accept-charset ' = ' utf-8,*;q=0.5 ', ' accept-encoding ' = ' gzip,deflate,sdch ', ' accept-language ' =&G T ' zh-cn,zh;q=0.8 ', ' Connection ' = ' keep-alive ', ' content-type ' = ' application/x-www-form-urlencoded; Charset=utf-8 ', ' Referer ' = ' http://fuzhou.8684.cn/', ' user-agent ' = ' mozilla/5.0 ' (Windows NT 5.1) APPLEWEBK it/537.11 (khtml, like Gecko) chrome/23.0.1271.95 safari/537.11 ', ' x-requested-with ' = ' XMLHttpRequest ',)); $dat = C Url_exec ($ch); Var_dump (Curl_error ($ch));//curl_close ($ch); Var_dump ($dat);//var_dump (Curl_error ($ch));

But the output is
String (Reply) "Empty from server" bool (FALSE)

Reply content:

http://fuzhou.8684.cn/



My code is like this.

 ' */* ', ' accept-charset ' = ' utf-8,*;q=0.5 ', ' accept-encoding ' = ' gzip,deflate,sdch ', ' accept-language ' =&G T ' zh-cn,zh;q=0.8 ', ' Connection ' = ' keep-alive ', ' content-type ' = ' application/x-www-form-urlencoded; Charset=utf-8 ', ' Referer ' = ' http://fuzhou.8684.cn/', ' user-agent ' = ' mozilla/5.0 ' (Windows NT 5.1) APPLEWEBK it/537.11 (khtml, like Gecko) chrome/23.0.1271.95 safari/537.11 ', ' x-requested-with ' = ' XMLHttpRequest ',)); $dat = C Url_exec ($ch); Var_dump (Curl_error ($ch));//curl_close ($ch); Var_dump ($dat);//var_dump (Curl_error ($ch));

But the output is
String (Reply) "Empty from server" bool (FALSE)

I can only say that your curl manual is not serious, the CURLOPT_HTTPHEADER use of this option must be in your own imagination, in fact, it is not so, should

curl_setopt ($ch, Curlopt_httpheader, Array (    ' Accept: */* ',    ' accept-charset:utf-8,*;q=0.5 ',    ' Accept-encoding:gzip,deflate,sdch ',    ' accept-language:zh-cn,zh;q=0.8 ',    ' connection:keep-alive ',    ' content-type:application/x-www-form-urlencoded; Charset=utf-8 ',    ' referer:http://fuzhou.8684.cn/',    ' user-agent:mozilla/5.0 (Windows NT 5.1) applewebkit/ 537.11 (khtml, like Gecko) chrome/23.0.1271.95 safari/537.11 ',    ' x-requested-with:xmlhttprequest ',));

So read the manual carefully.

Add up. It was intended to use curl+ to collect 8684 of the data.
Later found that love to help the network has a free bus data API.
http://www.aibang.com/api/

Check out the PHP manual.
Landlord will code:

curl_setopt ($ch, Curlopt_httpheader, Array (    ' Accept ' = = ' */* ',    ' accept-charset ' = ' utf-8,*;q=0.5 ',    ' accept-encoding ' = ' gzip,deflate,sdch ',    ' accept-language ' = ' zh-cn,zh;q=0.8 ',    ' Connection ' = > ' keep-alive ',    ' content-type ' = ' application/x-www-form-urlencoded ', Charset=utf-8 ',    ' Referer ' = ' http://fuzhou.8684.cn/',    ' user-agent ' = ' mozilla/5.0 (Windows NT 5.1) applewebkit/537.11 (khtml, like Gecko) chrome/23.0.1271.95 safari/537.11 ',    ' x-requested-with ' = ' XMLHttpRequest ',));

Call the function curl_setopt Replace with Curl_setopt_array to try.

Curl does have a powerful function! I used to use Fsocket to send HTTP requests in the program, and then after trying curl, it felt convenient and much more flexible!

A blog post about curl, though simple, feels good!

Http://www.360weboy.com/web-service/c ...

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