【发布时间】:2017-01-05 12:17:29
【问题描述】:
您好,我正在尝试使用 GET 发送一些 json 数据。
我试过用这种方式
This is the url = localhost/index.php/getRequest?name=BestRate&secret=masnadsapi
public function getRequest(){
$verb = $_SERVER['REQUEST_METHOD'];
if($verb == 'GET'){
if(isset($_GET['name']) && isset($GET['secret']) ){
$name = $_GET['name'];
$secret = $GET['secret'];
if($name == 'BestRate' && $secret == 'masnadsapi'){
$foo = array(
'Todays Best Rate' => '5.6%'
);
$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($foo));
}else{
return;
}
}else{
echo 'Masnad says : no parameter giving' ;
}
}
}
错误是消息:未定义的变量:GET 对于秘密部分。
【问题讨论】:
-
将
$GET['secret']更改为$_GET['secret'](在您使用它的两个地方)。 -
哦,谢谢!!!我根本没有注意到!
-
@MagnusEriksson 请写下答案,以便我接受!非常感谢
-
将其添加为答案。
标签: php json codeigniter url get