我与Microsoft Navision集成在一起。需要从那里获取/发送数据,但是当前面临通过PHP连接到服务的问题。这是我尝试过的:
<?php
require_once("NTLM/NTLMStream.php");
require_once("NTLM/NTLMSoapClient.php");
stream_wrapper_unregister('http');
stream_wrapper_register('http', 'NTLMStream') or die("Failed to register protocol");
$servicesURL = 'http://{IP}:{PORT}/TEST/WS/Services';
$baseURL = 'http://{IP}:{PORT}/TEST/WS/';
$CompanyName = "Company Name";
$pageURL = $baseURL.rawurlencode($CompanyName).'/Page/PolicyList';
echo "<br>URL of Item page: $pageURL<br><br>";
try{
$service = new NTLMSoapClient($pageURL);
var_dump($service);
}
catch (Exception $e) {
echo "<hr><b>ERROR: SoapException:</b> [".$e."]<hr>";
echo "<pre>".htmlentities(print_r($service->__getLastRequest(),1)).</pre>";
}
stream_wrapper_restore('http');
?>
问题是服务链接正在浏览器中运行,但是我无法通过PHP访问/连接它们。我收到以下错误:
**Gateway Timeout**
The gateway did not receive a timely response from the upstream server or application.
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from
'http://{IP}:{PORT}/TEST/WS/{Company Name}/Page/PolicyList' : Start tag expected,
'<' not found
在 CustomSettings.config 文件中启用了NTLM:
<add key="ServicesUseNTLMAuthentication" value="true" />
我还在请求中添加了服务器IP和身份验证详细信息(用户名:password):
class NTLMSoapClient extends SoapClient {
function __doRequest($request, $location, $action, $version, $one_way = 0) {
$headers = array(
'Method: POST',
'Connection: Keep-Alive',
'User-Agent: PHP-SOAP-CURL',
'Content-Type: text/xml; charset=utf-8',
'SOAPAction: "'.$action.'"',
);
$this->__last_request_headers = $headers;
$ch = curl_init($location);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//curl_setopt($ch, CURLOPT_POST, true );
//curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($ch, CURLOPT_USERPWD, 'username:password');
curl_setopt($ch, CURLOPT_INTERFACE, '{server IP which was whitelisted}');
$response = curl_exec($ch);
return $response;
}
function __getLastRequestHeaders() {
return implode("\n", $this->__last_request_headers)."\n";
}
}
我检查了数百个示例,文章,并跟踪它们在做什么,但仍然无法从服务中获得任何结果。我也检查了following answer,也检查了youtube video-完全一样,但是没有运气。
我在做错什么吗?