我正在使用codeigniter-3,在控制器内部,我点击了一个外部API,它给出了400个错误,但相同的 curl 请求,如果我点击了 Postman ,它的工作正常,你能请帮助我,我错过了什么..?
** Postman 的 curl 请求**
curl --location --request POST 'http://armycalling.com/baligaz-api/api/userapi/login' \
--header 'x-api-key: ccccc' \
--header 'Authorization: Basic YWRtaW46YmFsaWdheiFAIyQ=' \
--header 'Content-Type: application/json' \
--header 'Cookie: ci_session=f3630b226e539f4aa079e980e23cc730609a1627' \
--data-raw '{
"email" : "dummy@gmail.com",
"password" : "dummy.srk"
}'
usercontroller.php
if(isset($_POST['login']))
{
//phpinfo();
$url = 'http://localhost/login';
$u_name = $this->input->post('username');
$password= $this->input->post('password');
$curl = curl_init($url);
$data = [
'email'=>$u_name,
'password'=>$password
];
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'x-api-key: ccccc',
'Authorization: Basic YWRtaW46YmFsaWdheiFAIyQ=',
'Content-Type: Application/json',
'Cookie: ci_session=6dc4b8f72e2953c590ff503bd47f52ecfa158c79'
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
return print($httpcode);
curl_close($curl);
1条答案
按热度按时间laik7k3q1#
将此请求设置为使用Cookie会话并在POST请求中发送用户名/密码将产生成功登录。
这将产生: