Php 从web服务获取空白数组

Php 从web服务获取空白数组,php,web-services,curl,Php,Web Services,Curl,我在使用我在另一台服务器上创建的web服务时遇到了一个非常奇怪的问题 这是我创建的web服务的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_

我在使用我在另一台服务器上创建的web服务时遇到了一个非常奇怪的问题

这是我创建的web服务的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));
我也使用Curl,代码如下:

<?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));
?>
$curl=curl_init();
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($curl,CURLOPT_头,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\u exec($curl);
curl_close($curl);
回声';
打印(json解码($str));
请帮助我。

使用urlencode()

这项工作正在进行:



是否显示脚本的实际代码?另外,“尽快”在这里不是正确的思维方式。我没有看到任何代码。我重新发布了我的问题。谢谢,伙计,它现在可以处理curl和file\u get\u content()。谢谢,这不是问题:)如果你已经得到了答案,你现在可以把问题标记为已解决!
$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));
<?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));
?>