繁体   English   中英

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

[英]Trying to use curl to do a GET, value being sent is allows 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, 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可以是一个数组,其中键是名称,值是值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM