[英]How to deal with “Request denied by Throttle server” SOAP responses in Laravel 5
我已经制作了一个使用SOAP交换从Web API获取数据的Web应用程序。 最初,这是以一种过程性的方式完成的,现在我正尝试将其移入Laravel框架。 如果SOAP响应是“ Throttle服务器拒绝了请求”,我已经设置了向用户显示的view
但是我不知道如何检查该特定错误。 这是课程:
<?php namespace App\Models;
use SoapClient;
use Illuminate\Http\RedirectResponse;
class SoapWrapper {
public function soapExchange() {
// set WSDL for authentication and create new SOAP client
$auth_url = "http://search.webofknowledge.com/esti/wokmws/ws/WOKMWSAuthenticate?wsdl";
// set WSDL for search and create new SOAP client
$search_url = "http://search.webofknowledge.com/esti/wokmws/ws/WokSearch?wsdl";
// array options are temporary and used to track request & response data
$auth_client = @new SoapClient($auth_url);
// array options are temporary and used to track request & response data
$search_client = @new SoapClient($search_url);
// run 'authenticate' method and store as variable
$auth_response = $auth_client->authenticate();
// call 'setCookie' method on '$search_client' storing SID (Session ID) as the response (value) given from the 'authenticate' method
// check if an SID has been set, if not it means Throttle server has stopped the query, therefore display error message
if (isset($auth_response->return)) {
$search_client->__setCookie('SID',$auth_response->return);
} else {
return Redirect::route('throttle');
}
}
}
问题在于,它在$auth_response = $auth_client->authenticate();
时抛出“请求被Throttle服务器拒绝”的默认Laravel错误$auth_response = $auth_client->authenticate();
在到达if
语句之前,该语句检查SOAP Request是否返回了值(SessionID)。 当出于某种原因以程序方式设置它时,它没有执行此操作。
if
语句检查是否已从authenticate()
方法返回值,如果已返回,则将其(SessionID)分配给搜索客户端的cookie以授权搜索。 否则,它将显示自定义错误消息。
我尝试过使用is_soap_fault
但是由于它在技术上不是肥皂故障,因此无法捕获它。 我也尝试过删除导致问题的行并将if
语句更改为:
if (isset($auth_client->authenticate()->return) {...
但这也导致默认的Laravel SoapFault页面。 return Redirect::route('throttle')
向用户显示一个自定义错误页面,另存为throttle.blade.php
。
有人知道我如何测试油门错误吗?
没关系,在这里找到答案: 正确创建新的SoapClient时捕获异常 。
无论如何,我都会发布修改后的代码,以防将来对其他任何人有用:
<?php namespace App\Models;
use SoapClient;
use Illuminate\Http\RedirectResponse;
class SoapWrapper {
public function soapExchange() {
try {
// set WSDL for authentication and create new SOAP client
$auth_url = "http://search.webofknowledge.com/esti/wokmws/ws/WOKMWSAuthenticate?wsdl";
// set WSDL for search and create new SOAP client
$search_url = "http://search.webofknowledge.com/esti/wokmws/ws/WokSearch?wsdl";
// array options are temporary and used to track request & response data
$auth_client = @new SoapClient($auth_url);
// array options are temporary and used to track request & response data
$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) {
return Redirect::route('throttle');
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.