PHP file_get_contents()返回“无法打开流:HTTP请求失败!"
我在从PHP代码调用URL时遇到问题.我需要使用我的PHP代码中的查询字符串来调用服务.如果我在浏览器中输入url,就可以正常工作,但是如果我使用file-get-contents()进行调用,则会得到:
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:
警告:file-get-contents(http://....)无法打开流:HTTP请求失败! HTTP/1.1 202已在...中接受
Warning: file-get-contents(http://.... ) failed to open stream: HTTP request failed! HTTP/1.1 202 Accepted in ...
我正在使用的代码是:
$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');
这很好用...可能是我需要调用的网址中有第二个http://
吗?
This works fine... could it be that the url I need to call has a second http://
in it?
尝试使用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);
?>