简体   繁体   中英

PHP file_get_contents problem

I am having a problem with PHP's file_get_contents command.

$url = "http://api.rememberthemilk.com/services/rest/".$format.$auth_token.$filter."&api_sig=".$md5.$apikey.$method;

$content = file_get_contents($url);

$array = json_decode($content, true);
$taskname = $array['rsp']['tasks']['list']['taskseries']['name'];
$duedate = $array['rsp']['tasks']['list']['taskseries']['task']['due'];

($format, $auth_token, $filter, $md5, $apikey, $method are already defined in the script)

When I try to run this code this error is returned:

[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad request for line 101

line 101 = $content, = file_get_contents($url);

How to fix this? Thanks!!!

This url does not look great.

http://api.rememberthemilk.com/services/rest/?format=json&auth_token=AUTH_TOKEN& filter=dueWithin:"3 days of today"&api_sig=API_SIG&api_key=API_KEY&method=rtm.tasks.getList

Encode the tokens as follows:

$filter = 'filter='.urlencode( 'dueWithin:"3 days of today"' );

Use urlencode().

Try printing the URL after concatenating the variables. Then paste the URL into the address bar of your browser and see what comes back. Because it's a web service call, your browser might not know what to do with the response. In that case you might get additional information using the command-line user agent "curl", eg

curl -v 'http://some-url'

curl is built in to Macs and other *nix machines and is also available for Windows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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