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

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 尝试使用curl进行GET,发送的值允许为null脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用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可以是一个数组,其中键是名称,值是值.

脚本宝典总结

以上是脚本宝典为你收集整理的php – 尝试使用curl进行GET,发送的值允许为null全部内容,希望文章能够帮你解决php – 尝试使用curl进行GET,发送的值允许为null所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。