【问题标题】:angular 2 app response from Slim php is net::ERR_EMPTY_RESPONSE来自 Slim php 的 Angular 2 应用程序响应为 net::ERR_EMPTY_RESPONSE
【发布时间】:2017-07-18 08:46:45
【问题描述】:
    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 控制台错误消息: 选项http://www.delikates.co.il/backend/checkSignInnet::ERR_EMPTY_RESPONSE

例外:响应状态为:0,URL 为空

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

【问题讨论】:

  • 当我通过简单的 html 表单检查时,php 程序输入了重要的 if 语句: if (password_verify($jsonRequest->password,$hashed_pa​​ssword) and ($email_verified)) { $arr = $delikatesDbConnect ->json_user_details($id); $jsonResponse = json_encode($arr); $response = new HttpResponse($jsonResponse,202);返回$响应; }

标签: rest angular slim


【解决方案1】:

这似乎是您如何处理响应的问题。什么是 HttpResponse?

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

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

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

【讨论】:

  • 谢谢我的朋友,问题不是在程序中更进一步,$response 在哪里? .我最终确实从 $params 中检索了我想要检索的内容。
  • 不管怎样,我用你建议的命令替换了命令,但是没有用。
  • 问题出在这里 :if (password_verify($jsonRequest->password,$hashed_pa​​ssword) and ($email_verified)) { // echo "good"; $arr = $delikatesDbConnect->json_user_details($id); $jsonResponse = json_encode($arr); $response = new HttpResponse($jsonResponse,202);返回$响应; }
  • 对不起,我误读了这个问题。我会删除。您使用的是 Slim 2 还是 Slim 3?
  • 我怎样才能知道哪个版本是我的苗条?我在所有其他文件中打开了我服务器上的 LICENSE 文件,但没有指定版本
猜你喜欢
  • 2017-05-26
  • 1970-01-01
  • 2018-01-16
  • 1970-01-01
  • 2018-02-05
  • 1970-01-01
  • 1970-01-01
  • 2014-07-24
  • 1970-01-01
相关资源
最近更新 更多