PHP警告:file_get_contents无法打开流:HTTP请求失败! HTTP/1.1 400错误请求 [英] PHP Warning : file_get_contents failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request

查看:393
本文介绍了PHP警告:file_get_contents无法打开流:HTTP请求失败! HTTP/1.1 400错误请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Codeigniter建立了本地DVD数据库,并输入了影片名称等.我想要做的是从

I have built a local DVD Database using Codeigniter, With film names etc in. What I am looking to do is load in more data for the film from this IMDB API.

但是我遇到以下错误:

遇到PHP错误

A PHP Error was encountered

严重性:警告

消息:file_get_contents(http://www.imdbapi.com/?i=&t=2 Fast 2 Furious)[function.file-get-contents]:无法打开流:HTTP请求失败! HTTP/1.1 400错误请求

Message: file_get_contents(http://www.imdbapi.com/?i=&t=2 Fast 2 Furious) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request

文件名:controllers/dvd.php

Filename: controllers/dvd.php

行号:92

此URI 复制到地址栏中返回json数据,但是当在我的页面中加载时,它会给我该错误.

Copying this URI into an address bar returns the json data, But when loading in my page it gives me that error.

值得注意的是,我正在本地主机上运行此特定站点.正如我刚刚熟悉Codeigniter一样.

It is worth noting I am running on a localhost this particular site. As I am just familiarising myself with Codeigniter.

我的代码是....

            // Send Query To IMDB Api

        $film_q = $film_name[0]->title;
        $imdb_uri = "http://www.imdbapi.com/?i=&t=$film_q";
        $json = file_get_contents($imdb_uri);
        $json = json_decode($json);

        print_r($json);

EDIT :进一步研究.单个电影名称似乎可以加载,所以我假设我需要以某种方式在空格中钻一个"+"?

EDIT : Looking further into this. Single word film names seem to load in ok, So I'm assuming I need to someway drill down a "+" into the spaces?

推荐答案

尝试urlencode():

 $film_q   = urlencode($film_name[0]->title);
 $imdb_uri = "http://www.imdbapi.com/?i=&t=$film_q";

这篇关于PHP警告:file_get_contents无法打开流:HTTP请求失败! HTTP/1.1 400错误请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆