sim800l和api rest的cookie问题

时间:2019-05-16 08:49:38

标签: php http cookies sim800

我已经制作了具有连接和断开功能的API REST。使用PHP的$_SESSION保存会话。

这项工作有效,但我使用sim800l连接到API却未使用$_SESSION,我认为sim800l不支持cookie。

在sim800l上测试:

AT+SAPBR=3,1,"APN","free" 
OK
AT+SAPBR=1,1
OK
AT+SAPBR=2,1
+SAPBR: 1,1,"10.112.215.42"

OK
AT+HTTPINIT
OK
AT+HTTPPARA="CID",1
OK
AT+HTTPPARA="URL","http://naviwatt.fr/api/setup/mail/a@a.a/*****"
OK
AT+HTTPACTION=0
OK
AT+HTTPREAD
OK

+HTTPACTION: 0,200,11
AT+HTTPREAD
+HTTPREAD: 11
{"level":0}
OK

返回函数

    /**
     * show the level of the connection
     * 0 if not connected
     * 1 if connected as a boat
     * 2 fi connected as a user
     */
    public function level() {
        header('Content-Type: application/json');

        //check if somone is connected 
        if (isset($_SESSION['loged'])){
            $res = array("level" => $_SESSION['loged']);
        } else {
            $res = array("level" => 0);
        }

        //send datas
        http_response_code(200);
        echo json_encode($res);
    }

日志部分

if ($pass === $userDao->findByMail($id)->getPassword()){
   $_SESSION['loged'] = 2;
   $_SESSION['user'] = $userDao->findByMail($id);
   $_SESSION['boats'] = $boatDAO->findByOwner($id);
} else {
   http_response_code(417);
}

这给我发送了一个级别:0,好像没有连接,但是当我在Insomnia或Firefox上测试正常时(级别2)

0 个答案:

没有答案