Php 我正在发送发帖请求,但拉威尔收到了
我正在向我的API“/API/authenticate”提交请求Php 我正在发送发帖请求,但拉威尔收到了,php,laravel,Php,Laravel,我正在向我的API“/API/authenticate”提交请求 Route::post('authenticate', 'api\authenticateController@authenticate'); 每次我发送“POST”请求时,服务器都认为我在发送“GET”请求 在$/public/index.php中,我添加了以下行以转储我正在使用的方法: if($_SERVER["REQUEST_URI"] == "/api/authenticate") { dd(Illumi
Route::post('authenticate', 'api\authenticateController@authenticate');
每次我发送“POST”请求时,服务器都认为我在发送“GET”请求
在$/public/index.php中,我添加了以下行以转储我正在使用的方法:
if($_SERVER["REQUEST_URI"] == "/api/authenticate") {
dd(Illuminate\Http\Request::capture());
}
我一直在
#method: "GET"
我参加过:
composer dumpautoload
composer update
php artisan cache:clear
php artisan route:clear
但是没有任何帮助。。。有什么问题吗
p、 在本地主机和测试中,我一直在使用PostMan;下面是我使用邮递员执行提交的屏幕截图:
下面是$\public\index.php文件的代码;你可以看到我在哪里做了dd()
与斜杠连接的配置有什么关系?我也遇到了同样的问题,当我发送像“site.com/url”这样的请求时,服务器将我重定向到“site.com/url/”。因此,我认为您需要检查ngninx/apache配置。显示您的表单代码。在发送表单中使用'method'=>'POST',您可能想用postman进行调试。我使用的是postman。在curl\u setopt\u数组中尝试CURLOPT\u POST=>1
。
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell <taylorotwell@gmail.com>
*/
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels nice to relax.
|
*/
require __DIR__.'/../bootstrap/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
if($_SERVER["REQUEST_URI"] == "/api/authenticate") {
dd(Illuminate\Http\Request::capture());
}
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://localhost/api/authenticate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"api_key\"\r\n\r\njLiHWIwfi3KwGCt7OhQtFa8AAg4Ca\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"user\"\r\n\r\npro\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\npassword\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
CURLOPT_HTTPHEADER => array(
"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}