pyo*_*yon 5 php session web-services soap-client
Noob问题.
我正在开发一个使用有状态Web服务的PHP Web站点.基本上,我的网站的"控制流程"如下:
我的问题是Web站点在请求之间丢失了Web Service的状态.如何使网站跟踪Web服务的状态?我正在使用PHP的标准SoapClient类.
我已经尝试将SoapClient对象序列化为会话变量:
# ws_client.php
<?php
function get_client()
{
if (!isset($_SESSION['client']))
$_SESSION['client'] = new SoapClient('http://mydomain/MyWS/MyWS.asmx?WSDL', 'r');
return $_SESSION['client'];
}
function some_request($input1, $input2)
{
$client = get_client();
$params = new stdClass();
$params['input1'] = $input1;
$params['input2'] = $input2;
return $client->SomeRequest($params)->SomeRequestResult;
}
function stateful_request($input)
{
$client = get_client();
$params = new stdClass();
$params['input'] = $input;
return $client->StatefulRequest($params)->StatefulRequestResult;
}
?>
# page1.php
<?php
session_start();
$_SESSION['A'] = some_request($_POST['input1'], $_POST['input2']);
session_write_close();
header('Location: page2.php');
?>
# page2.php
<?php
session_start();
echo $_SESSION['A']; // works correctly
echo stateful_request($_SESSION['A']); // fails
session_write_close();
?>
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我的代码出了什么问题?
您需要使用 http://php.net/manual/en/soapclient.getlastresponseheaders.php 查找服务器返回的“set-cookie”标头,然后使用 http://php.net/manual/en /soapclient.setcookie.php 在发送后续请求时设置该 cookie。抱歉,无法编写示例代码,因为我不懂 PHP。
| 归档时间: |
|
| 查看次数: |
4191 次 |
| 最近记录: |