【发布时间】:2020-06-13 05:26:18
【问题描述】:
$url='https://example.com/demo/webservice/register?auth_key=cghjcgfchai1723y12y321hjvbv1asdas';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS,$posted_data);
$response = curl_exec($ch);
if($response === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
$my_file = 'file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
fwrite($handle,$response);
}
curl_close($ch);
return $response;
regiter.php
public function register()
{
$key='cghjcgfchai1723y12y321hjvbv1asdas';
$secretKey=$this->input->get('auth_key');
if($key!=$secretKey)
{
echo json_encode(array("response"=>"error","result"=>array("message"=>"Invalid key ")));
exit;
}
print_r($_POST);
exit();
}
文件.txt
Array
(
[email] => testn@gmail.com
[std_name] => testing
[menu-590] => 1000SK
[sex] => MALE
[father_name] => xyz
[mother_name] => abc
[dob] => 2020-02-21
[phone] => 9876543211
[address] => GHAZIABAD
[pin] => 201206
[aadhar] => 123456789012
)
我正在使用 curl 将响应从 file.txt 文件返回到 register 文件,我只是使用 print_r($_POST) 来知道响应是否到来,但它向我显示空白数组。我不知道为什么?请帮帮我。
谢谢
【问题讨论】:
-
觉得你需要
curl_setopt($ch, CURLOPT_POST, 1); -
什么都没发生@NigelRen
标签: php rest api codeigniter curl