为什么file_get_contents()函数返回"未能打开流:HTTP请求失败"?! [英] Why file_get_contents() returns "failed to open stream: HTTP request failed!"?

查看:1101
本文介绍了为什么file_get_contents()函数返回"未能打开流:HTTP请求失败"?!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有从PHP调用code一个url问题。我需要用一个查询字符串从我的PHP code调用服务。如果我输入网址到浏览器,它工作正常,但如果我使用文件得到-内容()拨打电话,我得到:


  

警告:文件得到-内容(HTTP:// ....)未能打开流:HTTP请求失败! HTTP / 1.1 202 ......接受


在code我用的是:

<$p$p><$c$c>$query=file_get_contents('http://###.##.##.##/mp/get?mpsrc=http://mybucket.s3.amazonaws.com/11111.mpg&mpaction=convert格式= FLV');
回波($查询);

就像我说的 - 从浏览器中调用,它工作正常。有什么建议?

我也试图与另一个网址,如:

  $查询=的file_get_contents('http://www.youtube.com/watch?v=XiFrfeJ8dKM');

这工作得很好......这可能是因为我需要调用的URL有第二个的http://


解决方案

尝试使用卷曲。

 &LT; PHP$ curl_handle = curl_init();
curl_setopt($ curl_handle, CURLOPT_URL,'http://###.##.##.##/mp/get?mpsrc=http://mybucket.s3.amazonaws.com/11111.mpg&mpaction=convert格式= FLV');
curl_setopt($ curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($ curl_handle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ curl_handle,CURLOPT_USERAGENT,你的应用程序名称');
$查询= curl_exec($ curl_handle);
curl_close($ curl_handle);?&GT;

I am having problems calling a url from PHP code. I need to call a service using a query string from my PHP code. If I type the url into a browser, it works ok, but if I use file-get-contents() to make the call, I get:

Warning: file-get-contents(http://.... ) failed to open stream: HTTP request failed! HTTP/1.1 202 Accepted in ...

The code I am using is:

$query=file_get_contents('http://###.##.##.##/mp/get?mpsrc=http://mybucket.s3.amazonaws.com/11111.mpg&mpaction=convert format=flv');
echo($query);

Like I said - call from the browser and it works fine. Any suggestions?

I have also tried with another url such as:

$query=file_get_contents('http://www.youtube.com/watch?v=XiFrfeJ8dKM');

This works fine... could it be that the url I need to call has a second http:// in it?

解决方案

Try using cURL.

<?php

$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://###.##.##.##/mp/get?mpsrc=http://mybucket.s3.amazonaws.com/11111.mpg&mpaction=convert format=flv');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
$query = curl_exec($curl_handle);
curl_close($curl_handle);

?>

这篇关于为什么file_get_contents()函数返回&QUOT;未能打开流:HTTP请求失败&QUOT;?!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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