加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 尝试使用curl进行GET,发送的值允许为null

发布时间:2020-12-13 21:43:26 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试使用curl使用一个名为redirect_uri的参数进行简单的GET.被调用的php文件为$_GET [“redirect_uri”]打印出一个空字符串,它显示为红色=并且似乎没有发送任何内容. 代码来做get //Get code from login and display it$ch = curl_init();$url = 'http
我正在尝试使用curl使用一个名为redirect_uri的参数进行简单的GET.被调用的php文件为$_GET [“redirect_uri”]打印出一个空字符串,它显示为红色=并且似乎没有发送任何内容.
代码来做get

//Get code from login and display it
$ch = curl_init();

$url = 'http://www.besttechsolutions.biz/projects/facebook/testget.php';

//set the url,number of POST vars,POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_GET,1);
curl_setopt($ch,CURLOPT_GETFIELDS,"redirect_uri=my return url");

//execute post
 print "new reply 2 <br>";
 $result = curl_exec($ch);
 print $result;
// print "<br> <br>";
// print $fields_string;
 die("hello");

testget.php文件

<?php
print "red-";
print $_GET["redirect_uri"];


?>

解决方法

这就是我通常会收到请求的方式,希望它能帮到你:

// create curl resource
$ch = curl_init();

//return the transfer as a string
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

// Follow redirects
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);

// Set maximum redirects
curl_setopt($ch,CURLOPT_MAXREDIRS,5);

// Allow a max of 5 seconds.
curl_setopt($ch,CURLOPT_TIMEOUT,5);

// set url
if( count($params) > 0 ) {
    $query = http_build_query($params);
    curl_setopt($ch,"$url?$query");
} else {
    curl_setopt($ch,$url);
}

// $output contains the output string
$output = curl_exec($ch);

// Check for errors and such.
$info = curl_getinfo($ch);
$errno = curl_errno($ch);
if( $output === false || $errno != 0 ) {
    // Do error checking
} else if($info['http_code'] != 200) {
    // Got a non-200 error code.
    // Do more error checking
}

// close curl resource to free up system resources
curl_close($ch);

return $output;

在此代码中,$params可以是一个数组,其中键是名称,值是值.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读