Php 试图将GET或POST数据传递给Laravel评论应用程序

Php 试图将GET或POST数据传递给Laravel评论应用程序,php,post,laravel,laravel-4,get,Php,Post,Laravel,Laravel 4,Get,遵循以下GitHub应用程序的scotch.io教程: 完成本教程后,我想知道是否有可能通过URL将信息传递给预期的Laravel应用程序。我在网站上问了这个问题,但充其量反应很慢 这是我的路线信息 URI: POST api/comments Name: api.comments.store Action: CommentController@store 以下是我的控制器代码: <?php // app/controllers/CommentController.php cla

遵循以下GitHub应用程序的scotch.io教程:

完成本教程后,我想知道是否有可能通过URL将信息传递给预期的Laravel应用程序。我在网站上问了这个问题,但充其量反应很慢

这是我的路线信息

URI: POST api/comments

Name: api.comments.store

Action: CommentController@store
以下是我的控制器代码:

<?php
// app/controllers/CommentController.php

class CommentController extends \BaseController {

    /**
     * Send back all comments as JSON
     *
     * @return Response
     */
    public function index()
    {
        return Response::json(Comment::get());
    }

    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store()
    {
        Comment::create(array(
            'author' => Input::get('author'),
            'text' => Input::get('text')
        ));

        return Response::json(array('success' => true));
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function destroy($id)
    {
        Comment::destroy($id);

        return Response::json(array('success' => true));
    }

}

您可以使用
php
中的任何库,通过提交带有POST数据的
POST
请求来完成此操作。但在这种情况下,请确保禁用
csrf
过滤器以过滤对
store
方法的外部请求,或者生成一个持久令牌,并将其保存到tour端(在请求发出之前,可能暂时在数据库中的某个位置),因此如果请求包含生成的令牌,则可以检查其是否有效(如果需要)。因为如果在该方法上启用了
csrf
,并且请求是从没有令牌的外部资源发出的(当使用
form
类打开表单时,Laravel会自动为表单生成令牌),则请求无法到达该方法

使用带有POST数据的
POST
方法的
cURL
请求示例:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"url of laravel site");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('postvar1' => 'value1')));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
现在检查响应(
$server\u output
)。如果需要传递
csrf
令牌,则需要将其添加到
数组
内部
http\u build\u query
。这只是一个基本概念,请进一步研究。您也可以检查