来自Slim php的angular 2 app响应是net :: ERR_EMPTY_RESPONSE

时间:2017-02-27 16:29:07

标签: rest angular slim

    Hi everyone,

    this is the code in slim php:

    $app->post('/checkSignIn', function () use ($app) {
        $params =  $app->request->post()['body'] ;

        if(!empty($params))
        {
           $jsonRequest = json_decode($params);
            //echo $jsonRequest->email;

            $delikatesDbConnect = new DelikatesDbConnect ('localhost', 'gontar_delikates', 'DgDgDg11', 'gontar_delikates');
            $id = $delikatesDbConnect->findUserIdByMail($jsonRequest->email);
            //echo $id;
            if ($id>0) // if $id exists fetch hashed password and email_verfied values
            {
                $hashed_password = $delikatesDbConnect->findPasswordById($id);
                $email_verified = $delikatesDbConnect->findEmailVerifiedById($id);



                if (password_verify($jsonRequest->password,$hashed_password) and ($email_verified))
                {
                    $arr = $delikatesDbConnect->json_user_details($id);
                    $jsonResponse = json_encode($arr);
                    $response = new HttpResponse($jsonResponse,202);
                    return $response;
                }
                else
                {
                    return '';
                }

            }
            else
            {
                return '';
            }

        }
        else
        {
            return '';
        }
    })->name('register'); 

this is the request code in typscript ng2:

sendUserAndPass(userDetails:JSON)
  {
    const body = JSON.stringify(userDetails);
    console.log(body);
    const headers = new Headers();
    headers.append('Content-Type','application/json');
    this.http.post("http://www.delikates.co.il/backend/checkSignIn", body, {headers: headers})
        .subscribe((data:Response)=>console.log(data));
  }

为什么我会进入chrome console err这样的消息: 选项http://www.delikates.co.il/backend/checkSignIn net :: ERR_EMPTY_RESPONSE

EXCEPTION:响应状态:URL为0:null

未捕获的响应{_body:ProgressEvent,status:0,ok:false,statusText:“”,headers:Headers ...}

1 个答案:

答案 0 :(得分:0)

这似乎与您处理响应的方式有关。什么是HttpResponse?

处理响应的一种典型方法是使用现有的响应对象并写入。

return $response->withJson($arr, 202);

https://www.slimframework.com/docs/objects/response.html#returning-json