我一直在寻找解决这个问题的方法。请注意,我是Laravel的新手,但精通PHP。
从routes / web.php
Route::any('/server', 'SoapController@callServer');
Route::get('/client', function() {
$params = array(
'location' => 'http://localhost/soap/public/server'
,'uri' => 'urn://localhost/soap/public/server'
,'trace' => 1
);
$client = new \SoapClient(null, $params);
$id_array = array('id' => '1');
echo $client->__soapCall('getStudentName', $id_array);
});
从SoapController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Server;
class SoapController extends Controller
{
public function callServer() {
$params = array('uri' => 'soap/public/server');
$server = new \SoapServer(null, $params);
$server->setClass('App\Server');
$server->handle();
}
}
来自app / Server.php
namespace App;
class Server {
public function getStudentName($id_array) {
return 'Student Name';
}
}
当我运行http://localhost/soap/public/server时,它运行正常。但是当我运行http://localhost/soap/public/client时,Laravel会产生错误“未知状态”。
仅__soapCall()行会产生错误。参数已成功传输到函数。
请帮助。
答案 0 :(得分:1)
Edit app/Http/Middleware/VerifyCsrfToken.php in your laravel app to white-list your server url from CSRF verification like this:
class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
'*/images/upload',
'*/search',
'*/server' // add your server uri here.
];
}