php - Laravel REST API call returns dummy data with status 200
Get the solution ↓↓↓I am working on making mobile application backend apis. The api I am working on now is just getting user information. I am testing the api with Postman app.
When I call the api on the postman, it returns JSON data successfully, but sometimes it returns dummy data for same api call. And when I try again, it returns correct JSON data.
I am attaching two screens. Here is the issue:
Below shows correct response:
I am using Laravel5.1 and OAuth2 authentication module(lucadegasperi/oauth2-server-laravel) from Github. Server is hosted on Bluehost.
Here is laravel code:
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index($id = null)
{
if($id == null) {
$my_id = Authorizer::getResourceOwnerId();
return User::find($my_id);
}
else
return User::find($id);
}
I am struggling with this issue for a week and please help me. Thanks in advance.
Answer
Solution:
It looks like it has something to do with Incapsula. I don't know if this is something you setup, or if it is setup by your host, but the traffic to your website is going through Incapsula. Some of your POSTMAN requests are getting through fine, but some of them are being blocked by Incapsula, probably because they look like someone trying to scrape your site.
If you have control over this, you may want to whitelist your local IP while developing and testing.
Answer
Solution:
Bluehost is not providing incapsula service, but the server DNS is allocated on Godaddy before moving and Godaddy setup incapsula. I have parking domain on Bluehost and replacing the domain address on my codes, the issues disappeared.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: too few arguments to function laravel
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.