简体   繁体   English

PHP curl返回空白字符串

[英]PHP curl returning blank strings

I started off using file_get_contents() and it returned string(9259) in which every character is a space (aka. its a lot of empty). 我开始使用file_get_contents() ,它返回string(9259),其中每个字符都是一个空格(也就是很多空白)。 After some research I tried using curl() and after a few struggles with getting the CURLOPT_SSL_VERIFYPEER and CURLOPT_USERAGENT to work it brought me right back to where I was, string(9259) of all blank. 经过一番研究后,我尝试使用curl()并且在使CURLOPT_SSL_VERIFYPEERCURLOPT_USERAGENT正常工作之后,经过几次努力,它使我回到了原来的状态,所有空白的string(9259)都恢复了。

I am attempting to retrieve the tracking information on multiple packages automatically and the code for a single iteration is as follows: 我正在尝试自动检索多个包上的跟踪信息,并且单次迭代的代码如下:

function curl($url)
    {
        $ch = curl_init();
        curl_setopt( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17' );
        curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false  );
        curl_setopt( $ch, CURLOPT_URL, $url );
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
        $data = curl_exec( $ch );
        var_dump( curl_getinfo( $ch ) );
        echo curl_errno( $ch ) . '<br/>';
        echo curl_error( $ch ) . '<br/>';
        curl_close( $ch );
        return $data;
    }

$url for one instance is https://www.fedex.com/fedextrack/?tracknumbers=055575670028673&cntry_code=us 一个实例的$ url是https://www.fedex.com/fedextrack/?tracknumbers=055575670028673&cntry_code=us

My question is essentially why am I receiving the string(9259) of blank characters? 我的问题本质上是为什么我会收到空​​白字符的string(9259)? I expected to receive an actual string representation of the website. 我希望收到该网站的实际字符串表示形式。

Maybe Fedex doesn't like it when you scrape pages, has detected that you are doing so, and is returning dummy data? 当您抓取页面,检测到您正在抓取页面并返回伪数据时,也许Fedex不喜欢它?

They do have APIs for this: http://www.fedex.com/us/developer/web-services/index.html 他们确实为此提供了API: http//www.fedex.com/us/developer/web-services/index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM