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

标签 php curl get

我正在尝试使用 curl 通过一个名为 redirect_uri 的参数执行简单的 GET。被调用的 php 文件为 $_GET["redirect_uri"] 打印出一个空字符串,它显示为 red= 并且似乎没有发送任何内容。 获取代码

//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, CURLOPT_URL, "$url?$query");
} else {
    curl_setopt($ch, CURLOPT_URL, $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,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7516863/

相关文章:

php - 如何显示数据库中两个用户之间的相互关系?

php - 连接到 etws.etrade.com 的未知 SSL 协议(protocol)错误 :443

java - 如何修复 "401 Unauthorized. No Api Key provided"

json - 使用 httparty ruby​​gem 发出 api 请求时如何处理分页

php - 在配置文件中访问 session 或 Yii

php - HTML Purifier - 转义不允许的标签而不是剥离

php - Mysql查询字段中匹配id

python - Python 请求中的 CURL -T(--upload-file 等效项)

c - 使用 libcurl 发送第一封无效电子邮件后,SMTP 连接就中断了。这是 "feature"还是我搞砸了?

javascript - Vue.js - this.data 不存储 GET 响应