从第三方API发布到Laravel 5 [英] Post to Laravel 5 from 3rd party API

查看:65
本文介绍了从第三方API发布到Laravel 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel 5构建一个基本应用程序.

I'm using Laravel 5 to build a basic app.

我正在使用第三方SMS网关,该网关接收SMS并将结果POST发送到我的应用程序.我正在使用Postman for Chrome和Requestb.in

I'm using a third party SMS gateway which takes an SMS and POST the results to my app. I'm testing it locally using Postman for Chrome, and Requestb.in

我的问题: 当我尝试发布到我的应用程序时,我从Laravel收到错误消息"whoops",状态码为405.

My Problem: When I try to POST to my app, I get a "whoops" error from Laravel, status code 405.

我的Hunch: 我感觉这是因为默认CSRF失败.该请求来自我的应用程序生态系统之外.

My Hunch: I have a feeling this is because of default CSRF failing. The request is coming from outside of my app's ecosystem.

在我的路线上,我有:

Route::post('/sms/', 'SMSController@create');

SMSController:

public function create(Request $request)
    {
       //keeping it simple for now
        return view('hello');
    }

问题:这是问题吗?如果是这样,如何仅从一条路由禁用CSRF.

Question: Is this the problem, and if so, how do I disable CSRF from one route only.

非常感谢!

推荐答案

我刚刚意识到L5现在具有排除列表功能:

I just realized that L5 now has exclusion lists as a feature:

<?php namespace APPNAMESPACE\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
          'example1',
          'example2/example3',
    ];
}

这篇关于从第三方API发布到Laravel 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆