doumigu9594
2016-08-20 04:26
浏览 203
已采纳

Laravel REST API调用返回状态为200的虚拟数据

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: enter image description here

Below shows correct response:

enter image description here

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.

图片转代码服务由CSDN问答提供 功能建议

我正在制作移动应用程序后端apis。 我现在正在处理的api只是获取用户信息。 我正在使用Postman应用程序测试api。

当我在邮递员上调用api时,它会成功返回JSON数据,但是 有时它会为同一个api调用返回虚拟数据。 当我再次尝试时,它返回正确的JSON数据。

我附加了两个屏幕。 这是问题:

下面显示了正确的响应:

< / p>

我正在使用Github的Laravel5.1和OAuth2身份验证模块(lucadegasperi / oauth2-server-laravel)。 Server托管在Bluehost上。

这是laravel代码:

  / ** 
 *显示资源列表。
 * 
 * @return \ Illuminate  \ Http \ Response 
 * / 
公共函数索引($ id = null)
 {
 if if($ id == null){
 $ my_id = Authorizer :: getResourceOwnerId(); 
 return user:  :find($ my_id); 
} 
 else 
返回User :: find($ id); 
} 
   
 
 

我正在努力解决这个问题 问题一周,请帮助我。 谢谢提前。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongzhihong3940 2016-08-20 05:18
    已采纳

    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.

    已采纳该答案
    打赏 评论
  • duanmao1932 2016-08-26 16:11

    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.

    打赏 评论

相关推荐 更多相似问题