从Web服务获取空白数组

问题描述:

我在使用另一台服务器上创建的Web服务时遇到了一个非常奇怪的问题。从Web服务获取空白数组

这是Web服务,我创建

http://52.53.227.143/API_test.php?post_name=BSN%20Syntha-6%20Isolate

我不能能够数组或我的网站上的任何其他格式接收数据的URL。我同时使用file_get_content和curl来接收json格式,但它只给了我空白数组。

这里是我的代码:

$post_name = 'BSN Syntha-6 Isolate'; 
$base = "http://52.53.227.143/API_test.php?post_name=".$post_name; 
$str = file_get_contents($base); 
echo '<pre>'; 
print_r(json_decode($str)); 

它给我下面的结果:

stdClass Object 
(
[info] => Array 
    (
    ) 

) 

我也用卷曲,下面的代码:

$curl = curl_init(); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($curl, CURLOPT_HEADER, false); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($curl, CURLOPT_URL, $base); 
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3'); 
curl_setopt($curl, CURLOPT_REFERER, 'http://www.google.com'); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); 
$str = curl_exec($curl); 
curl_close($curl); 
echo '<pre>'; 
print_r(json_decode($str)); 

请帮助我。

+0

显示脚本的实际代码吧? “尽快”在这里也不是正确的心态。 – Jakumi

+0

我没有看到任何代码。 – Jakumi

+0

我转发了我的问题。 –

使用urlencode()来

这是现在的工作:

<?php 
    $post_name = 'BSN Syntha-6 Isolate'; 
    $base = "http://52.53.227.143/API_test.php?post_name=" . urlencode($post_name); 
    $str = file_get_contents($base); 
    echo '<pre>'; 
    print_r(json_decode($str)); 
?> 
+0

感谢他,现在正在使用curl和file_get_content()。非常感谢 –

+0

不是问题:)如果您已经得到答案,您现在可以将问题标记为已解决! – mrid