cURL没有返回任何值

时间:2015-02-19 18:23:37

标签: php curl get

我对cURL的使用不熟悉,但它现在已成为我正在进行的项目的核心,我需要一些帮助。

我有一个带有PHP脚本的页面,它将通过cURL请求传递GET值,以便返回一个json字符串。

然后我需要解析json,以便将结果值用作连续GET到另一页的变量。

我的代码如下:

$user_login = 'xxxxxx';
$user_id = 'xxxxxx';


// Define the URL where we will be sending a request for a random key
$api_url = "http://mywebsite.com/autologin-api/";

// Set the parameters
$params = array(
    'action'            => 'get_login_key',
    'key'               => $user_id,
    'user_login'       => $user_login
);

// Send the data using cURL
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$gbi_response = curl_exec($ch);
curl_close($ch);

// Parse the response
parse_str($gbi_response);

// Convert the response to an array
$data = json_decode($gbi_response, true);

// Set the received key to a variable
$key = $data['key'];


echo "<a href='http://mywebsite.com/login/?key=" . $key . "'>Go and login</a>"; 

我知道另一方面的PHP脚本运行正常,因为如果我在浏览器中访问网址,传递上面的参数我可以看到json响应。然而,cURL总是空着。

我几乎到处都在线查看,尝试不同的cURL命令组合/变体,总是没有结果。

有人能帮我一把吗?

非常感谢您的时间和帮助。

0 个答案:

没有答案
相关问题