0

I have changed the HTTP status code in my json response using Laravel. It's working fine in localhost but the same code not working WHM server.

Laravel Version : 7

PHP Version : 7.4

My code

$encode = ['code' => 400,'message'  => 'Token is Invalid','data' => []];
return Response::make(json_encode($encode,JSON_PRETTY_PRINT|JSON_FORCE_OBJECT),401)->header('Content-Type',"application/json");

Local host Response

enter image description here

Server Response enter image description here

Please anyone help to resolve this.

Thanks in advance..

3 Answers 3

1

i don't worked with laravel so can't help you about laravel

but you can solve your problem self with php

set your http code via header

header('HTTP/1.1 401 Unauthorized');
Sign up to request clarification or add additional context in comments.

Comments

1

try this

return response()->json(['error' => 'Unauthenticated.'], 401);

1 Comment

This also return the same response.
0

try this one

   $response = ['code' => 401,'message'  => 'Token is Invalid','data' => []];
   return response($response, 401);

1 Comment

so problem is about your server and your php build. test it in another server (not local machines)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.