【发布时间】:2016-08-22 13:11:06
【问题描述】:
我有一个 laravel api,我正在尝试运行自定义工匠命令来处理事务。该 api 应该检查我们的商家数据库中的待处理交易并将它们发布到我们的交易数据库中。 我收到以下错误:
[GuzzleHttp\Exception\ClientException]
Client error: `POST http://paycentral.mymarket.com/transactions/bulk` resulted in a `405 Method Not Allowed` response:
{"error":{"message":"405 Method Not Allowed","status_code":405,"debug":{"line":446,"file":"\/var\/www\/vhosts\/maindomai (truncated...)
我使用的 API 位于 api.mymarket.com。搜索这样的错误让我相信这是一个与 CORS 相关的问题。我正在使用 laravel-cors,并在 api.mymarket.com 和 paycentral.mymarket.com 的公共文件夹中的 .htaccess 中添加了 Header set Access-Control-Allow-Origin "*"。该错误仍然存在。还有其他可能的解决方法吗?我们目前正在使用 plesk 作为我们的托管服务。
更新:我尝试在支付子域中进行预检请求 来源:api.mymarket.com 访问控制请求方法:POST 访问控制请求标头:MM
它返回了 500 内部错误,我猜这是进展。
更新 这是 paycentral 的 routes.php。 cors-library 在 app.php 中注册。
paycentral routes.php
<?php
$api = app('Dingo\Api\Routing\Router');
// all routes are protected by the Authenticate middleware which makes sure the client
// is authenticated as *somebody* - each resource is further protected by the authorization
// policies in the App\Api\V1\Policies files to limit the method calls by which client
// type is attempting to access the resource - these must be mapped in the AuthServiceProvider
$api->group([
'version' => 'v1',
'namespace' => 'App\Api\V1\Controllers',
'middleware' => 'auth' // use the Authenticate middleware
], function($api) {
/*
* partial CRUD resource routes
*/
$api->get('transactions/{id}', 'TransactionController@show');
$api->post('transactions', 'TransactionController@store');
$api->put('transactions/{id}', 'TransactionController@update');
$api->post('transactions/bulk', 'TransactionController@store_bulk');
$api->post('transactions/get_updates', 'TransactionController@get_updates');
【问题讨论】:
-
你确定
route.php中的路由定义吗?? -
您是否将
laravel-cors库中的中间件添加到您的所有路由或特定路由?此外,它可能根本不是 CORS 问题,因为它可能会给您一个飞行前请求错误。 -
如果你发出 curl 请求,它不应该与 CORS 有任何关系。仅当您发出跨域请求(即不同域)时才使用 CORS。
-
它们是两个不同的子域,但我认为它们也适用。
-
请告诉我们
http://paycentral.mymarket.com/transactions/bulk的路由定义?
标签: php web-services laravel