[英]How to send data between two server using CURL in Codeigniter?
I have two Servers: 我有两台服务器:
1. Licensing 1.许可
2. Provisioning 2.供应
Now a client(android/ios device) sends a request to license server. 现在,客户端(android / ios设备)将请求发送到许可证服务器。 So there we get some parameters from GET which I forward to Provisioning server, using CURL like this: 因此,我们使用CURL从GET获取一些参数,然后将其转发到Provisioning服务器,如下所示:
$skey = $this->input->get('site_id');
$uid = $this->input->get('user_id');
$url = "http://127.0.0.1/example.com?site_key=".$skey."&uid=".$uid;
$wget_cmd = "wget --no-check-certificate \"".$url."\" >/dev/null 2>/dev/null ";
//echo($wget_cmd);
//exec($wget_cmd);
// create a new cURL resource
$ch = curl_init();
//curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
curl_exec($ch);
echo curl_error($ch);
// close cURL resource, and free up system resources
curl_close($ch);
Now the provisioning server has a file called provisioning.php . 现在,配置服务器具有一个名为Provisioning.php的文件。 There I perform some DB operations based on the request from License server and generate a URL which I want to send back to the license server. 在那里,我根据许可证服务器的请求执行一些数据库操作,并生成要发送回许可证服务器的URL。
On provisioning I generate a URL like this based on DB operations: 在配置时,我会基于数据库操作生成一个类似这样的URL:
$uri = site_url('/uploads/'.$user_ini['custom_ini_filename'].'.ini');
$ini_url = json_encode($uri,JSON_UNESCAPED_SLASHES);
Here I want to return this $ini_url
back to license server. 在这里,我想将此$ini_url
返回给许可证服务器。
- How do I do this? 我该怎么做呢?
- How to access this
$ini_url
on the license server ? 如何在许可证服务器上访问此$ini_url
?
Set CURLOPT_RETURNTRANSFER to 1 and simply assign the response from curl_exec($ch) to a variable: 将CURLOPT_RETURNTRANSFER设置为1,只需将curl_exec($ ch)的响应分配给一个变量:
License Server 许可服务器
$skey = $this->input->get('site_id');
$uid = $this->input->get('user_id');
$url = "http://127.0.0.1/example.com?site_key=".$skey."&uid=".$uid;
$wget_cmd = "wget --no-check-certificate \"".$url."\" >/dev/null 2>/dev/null ";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
curl_setopt($ch, CURLOPT_URL, $url);
// The blow variable stores the response from provision server
$response_from_provision_server = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
You will also need to echo the contents of $ini_url from the provision server, this being the output that is sent back to License Server in response to the curl_exec() call. 您还需要从配置服务器回显$ ini_url的内容,这是响应curl_exec()调用而发送回许可证服务器的输出。
Provisioning Server 供应服务器
$uri = site_url('/uploads/'.$user_ini['custom_ini_filename'].'.ini');
$ini_url = json_encode($uri,JSON_UNESCAPED_SLASHES);
// echo the $ini_url variable
echo $ini_url;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.