Php CodeIgniter控制器仅响应浏览器
我在gcloud中建立了一个codeigniter项目,我写了一篇简单的文章,并获得如下控制器:Php CodeIgniter控制器仅响应浏览器,php,codeigniter,Php,Codeigniter,我在gcloud中建立了一个codeigniter项目,我写了一篇简单的文章,并获得如下控制器: public function test2() { echo "hello" } public function test() { $input_data = json_decode(trim(file_get_contents('php://input')), true); print_r($input_data); } 当你在这里测试它时 当我在浏览器中调
public function test2() {
echo "hello"
}
public function test() {
$input_data = json_decode(trim(file_get_contents('php://input')), true);
print_r($input_data);
}
当你在这里测试它时
<?php
post();
echo "<hr>";
get();
function post() {
$ch = curl_init();
$url1 = 'https://rbm2018-123.appspot.com/api/member/test';
$url2 = 'localhost/nrb-website/api/member/test';
$payload = `{
"qwerty": 1234,
"comeon": "sdgsdkjsdfsdgf"
}`;
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url2,
CURLOPT_HTTPHEADER => array('Content-Type:application/json'),
CURLOPT_USERAGENT => 'Codular Sample cURL Request',
CURLOPT_POSTFIELDS => $payload
));
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
}
function get() {
$ch = curl_init();
$url1 = 'https://rbm2018-123.appspot.com/api/member/test2';
$url2 = 'localhost/nrb-website/api/member/test2';
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url2,
CURLOPT_USERAGENT => 'Codular Sample cURL Request'
));
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
}
?>
url1和url2的CURL post没有响应任何结果
url2的CURL get响应了一个结果,但url2没有响应。看起来CodeIgniter阻止了“file\u get\u contents('php://input“)”-请求,查看此 还可以检查PHP错误,它们可以提供很多帮助。我在我的开发服务器上使用了最多的display_Errors=true
我希望这能帮助你我发现了,我需要补充
google_app_engine.enable_curl_lite = "1"
到我的应用程序根目录中的php.ini以使其工作注意:您没有在url2中添加http://请检查它