Elb*_*rto 2 php soap http soap-client
我正在尝试提取 Soap 响应的 HTTP 状态代码。所以例如我有:
$client = new SoapClient($wsdl);
$client->__setSoapHeaders(
new SoapHeader(
$nameSpace,
'Security',
$secHeaderValue,
true
)
);
// The actual call
$response = $client->Complete($paramswebservice)
Run Code Online (Sandbox Code Playgroud)
所以现在我得到了响应头,这样:
$responseHeaders = $client->__getLastResponseHeaders();
var_dump($responseHeaders);
Run Code Online (Sandbox Code Playgroud)
这是 vardump 的结果:以这种方式格式化的字符串(网络浏览器 - 页面源代码)
我现在正在做的是提取 http 状态代码“200”:
/**
* Returns the HTTP Status code of $response
* @param string $response
* @return string
*/
function extract_response_http_code($response) {
$tmp = explode('\n', $response);
$array = explode(' ', $tmp[0]);
return $array[1];
}
Run Code Online (Sandbox Code Playgroud)
我真的不喜欢这个解决方案。我想要一个更强大/一致的。有什么建议 ?
编辑 1
正如评论中所问:
HTTP/1.1 200 正常 缓存控制:私有,最大年龄=0 内容长度:1315 内容类型:文本/xml;字符集=utf-8 服务器:Microsoft-IIS/8.5 X-Powered-By: ASP.NET 日期:2017 年 3 月 30 日星期四 08:52:15 GMT
<?php
$result="HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Length: 1315
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
Date: Thu, 30 Mar 2017 08:52:15 GMT";
preg_match("/HTTP\/\d\.\d\s*\K[\d]+/", $result,$matches);
print_r($matches);
Run Code Online (Sandbox Code Playgroud)
输出:
Array
(
[0] => 200
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4334 次 |
| 最近记录: |