PHP CURL到CodeIgniter控制器 [英] PHP CURL to CodeIgniter controller
本文介绍了PHP CURL到CodeIgniter控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
<?php
$url = 'http://localhost:2304/index.php/testproj/files/add/';
$name = "test";
$fields = array(
'name'=>urlencode($name)
);
$fields_string = "";
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
var_dump($result);
//close connection
curl_close($ch);
?>
我正在尝试将发布数据发送到CodeIgniter控制器。我决定使用CURL来完成这项工作。但是,它不起作用,当我在控制器中放置 blah时,它不会返回任何内容。当我直接访问URL时,它显示等等。
I am trying to send post data to a CodeIgniter controller. I decided to use CURL to do the job. however, it doesn't work, when I put "blah" in my controller, it doesn't return anything. When I access the URL directly, it shows "blah".
推荐答案
您可以使用我的卷曲库:
$this->load->library('curl');
$result = $this->curl->simple_get('http://example.com/');
var_dump($result);
这篇关于PHP CURL到CodeIgniter控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文