我有一个应用程序,用户在其中提交一个表单,该表单执行SOAP交换以从Web API获取一些数据。如果在特定时间内有太多请求,Throttle服务器将拒绝访问。我为此创建了一个自定义错误视图,该视图throttle.blade.php
保存在下resources\views\pages
。在此,routes.php
我将路线命名为:
Route::get('throttle', 'PagesController@throttleError');
在PagesController.php
我添加相关的功能为:
public function throttleError() {
return view('pages.throttle');
}
这是SoapWrapper
我创建的用于执行SOAP交换的类:
<?php namespace App\Models;
use SoapClient;
use Illuminate\Http\RedirectResponse;
use Redirect;
class SoapWrapper {
public function soapExchange() {
try {
// set WSDL for authentication
$auth_url = "http://search.webofknowledge.com/esti/wokmws/ws/WOKMWSAuthenticate?wsdl";
// set WSDL for search
$search_url = "http://search.webofknowledge.com/esti/wokmws/ws/WokSearch?wsdl";
// create SOAP Client for authentication
$auth_client = @new SoapClient($auth_url);
// create SOAP Client for search
$search_client = @new SoapClient($search_url);
// run 'authenticate' method and store as variable
$auth_response = $auth_client->authenticate();
// add SID (SessionID) returned from authenticate() to cookie of search client
$search_client->__setCookie('SID', $auth_response->return);
} catch (\SoapFault $e) {
// if it fails due to throttle error, route to relevant view
return Redirect::route('throttle');
}
}
}
在达到Throttle服务器所允许的最大请求数量之前,一切都会正常进行,此时应显示我的自定义视图,但会显示错误:
InvalidArgumentException in UrlGenerator.php line 273:
Route [throttle] not defined.
我不知道为什么要说未定义路线。
您没有为路线定义名称,仅为路径定义。您可以这样定义路线:
Route::get('throttle', ['as' => 'throttle', 'uses' => 'PagesController@throttleError']);
该方法的第一部分是您定义的路线路径,例如/throttle
。作为第二个参数,您可以传递带有选项的数组,您可以在其中指定路由(as
)和回调的唯一名称(在本例中为控制器)。
您可以在文档中阅读有关路线的更多信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句