webman返回json响应头错误

langbin
 // 参数验证错误
         if ($exception instanceof ValidateException) {
            return json($exception->getError(), 422);
        }
        if($exception instanceof ApiException){
        //加以下两行也没有用。响应头还是 text/html; charset=UTF-8
            //$response = response();
           // $response->header('Content-Type', 'application/json');
            return json(['code'=>$exception->getCode(),'msg'=>$exception->getMessage()]);
        }
        // 请求异常
        if ($exception instanceof HttpException && request()->isAjax()) {
            return response($exception->getMessage(), $exception->getStatusCode());
        }
        return parent::render($request, $exception);
    }
2039 1 0
1个回答

keytehu

webman的json方法自带 Content-Type application/json

  • langbin 2021-10-20

    问题是用json这个也是没有作用,然后我就想着手工添加。发现最后还是没有作用

  • keytehu 2021-11-04

    Content-Type application/json 已经发了,如果是前端不识别的话看下前端是不是有什么问题

年代过于久远,无法发表回答
🔝