我正在使用标准的SoapClient类向付款服务器发出请求。
$context = stream_context_create([
'http' => [
'follow_location' => 0,
],
]);
$options = [
'uri' => 'urn:PaymentServer',
'location' => 'http://localhost:8001/index.php',
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'trace' => true,
'soap_version' => SOAP_1_1,
'stream_context' => $context,
'connection_timeout' => 50,
];
$soapClient = new SoapClient(null, $options);
try {
var_export($soapClient->GetPayment([]));
} catch (Throwable $e) {
echo $e->getMessage();
var_export($soapClient->__getLastResponse());
}
脚本http://localhost:8001/index.php包含以下代码
header('Location: http://example.com', true, 302);
exit;
我期望结果为空,但实际输出包含来自example.com的HTML
我在相同的流上下文中尝试过get_file_contents
函数:
var_export(file_get_contents('http://localhost:8001/index.php', false, $context));
我有空字符串。
应设置哪些SoapClient或流上下文选项以防止重定向?