我在我的网络应用程序中使用 codeigniter 3.0。我想点击一个 URL 然后返回到一个 View 。假设点击一个按钮,我想点击一个 API,然后返回到带有成功消息的同一 View 。有人可以帮忙吗?
我的API是http://wmlab.in/api/getData.php?username=web
我尝试了 file(' http://wmlab.in/api/getData.php?username=web ') 但它不起作用。
最佳答案
使用curl来做到这一点,如果您的服务器没有curl,也可以安装curl。
url="http://wmlab.in/api/getData.php?username=web";
function getUrlContent($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$data = curl_exec($ch);
echo $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return ($httpcode>=200 && $httpcode<300) ? $data : false;
}
$content=getUrlContent($url);
echo $content;
关于Codeigniter 点击一个 url 并返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31666794/