[英]Blank Response on a cURL Request PHP
I am making an API request using cURL but I'm getting a blank result. 我正在使用cURL发出API请求但是我得到一个空白的结果。 I tried to var_dump
the url then tried the url on the browser and works fine. 我尝试var_dump
url然后在浏览器上尝试了url并且工作正常。 Here's my code. 这是我的代码。
$parameters = array(
"user" => urlencode('xxxx'),
"password" => urlencode('xxxx'),
"msisdn" => urlencode('09277878067'),
"type" => urlencode('full'),
);
$post_data = '';
//create name value pairs seperated by &
foreach($parameters as $k => $v)
{
$post_data .= $k . '='.$v.'&';
}
// Remove the & from the last
$post_data2 = rtrim($post_data, '&');
$url = "http://www.telcoportal.com/hlr/check?";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url.$post_data2);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$output=curl_exec($ch);
curl_close($ch);
var_dump($output);
var_dump($url.$post_data2);
exit();
The $url.$post_data2
is http://www.telcoportal.com/hlr/check?user=xxxx&password=xxxx&msisdn=09277878032&type=full
which when you checked the browser gives a response {"status":"error","remark":"Authentication Failed"}
. $url.$post_data2
是http://www.telcoportal.com/hlr/check?user=xxxx&password=xxxx&msisdn=09277878032&type=full
,当您检查浏览器时会给出回复{"status":"error","remark":"Authentication Failed"}
。 But my $output
is blank and not getting anything. 但我的$output
是空白的,没有得到任何东西。
You should use curl_getInfo function to get the information about you session. 您应该使用curl_getInfo函数来获取有关您的会话的信息。 Here is the url http://php.net/manual/en/function.curl-getinfo.php 这是网址http://php.net/manual/en/function.curl-getinfo.php
For your case the test should work. 对于您的情况,测试应该工作。
if(!curl_errno($ch))
{
$info = curl_getinfo($ch);
echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
}
curl_close($ch); curl_close($ CH); ?> ?>
Try using echo curl_errno($ch);
尝试使用echo curl_errno($ch);
to get the error code returned from the call. 获取从调用返回的错误代码。
http://php.net/manual/en/function.curl-errno.php http://php.net/manual/en/function.curl-errno.php
Found it. 找到了。 It's the they use https
. 这是他们使用https
。 it's working now. 它现在正在运作。 Sorry for the noob question. 抱歉,这个菜鸟问题。 thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.