【发布时间】:2016-10-25 21:05:34
【问题描述】:
我们正在向 microsoft exchange server 2016 发出肥皂请求。来自 cli 脚本和肥皂客户端的请求正在运行。从浏览器调用时,具有相同请求 xml 的相同脚本将不起作用。
class testClass extends SoapClient {
public $user = 'username';
public $password = 'password';
function __doRequest($request, $location, $action, $version, $one_way = NULL) {
$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;
$request = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Body>
<DeleteItem DeleteType="HardDelete" SendMeetingCancellations="SendToAllAndSaveCopy" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<ItemIds>
<t:ItemId Id="AAANAG9wQHRmaHMubHUuc2UARgAAAAAAoeCyBeBA7EGXcncI4cCeZwcAnd+iJ87BLkGneeHHldhNdAAAABB5VAAAnd+iJ87BLkGneeHHldhNdAAA1wzUcAAA"/>
</ItemIds>
</DeleteItem>
</soap:Body>
</soap:Envelope>';
$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, $this->user.':'.$this->password);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.json');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.json');
$response = curl_exec($ch);
if(!trim($response) == "")
return $response;
else
return "no resp";
unlink("cookies.json");
}
}
$result = $client->DeleteItem($DeleteItem);
var_dump($result);
我们已经检查并确保我们有 openssl、curl、soapclient 扩展。 从浏览器请求时出现以下错误。
Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document in
C:\xampp\htdocs\test\wsdl2phpgenerator\xmltfhs\test.php:140 Stack trace: #0
C:\xampp\htdocs\test\wsdl2phpgenerator\xmltfhs\test.php(140): SoapClient->__call('DeleteItem', Array) #1
C:\xampp\htdocs\test\wsdl2phpgenerator\xmltfhs\test.php(140): testClass->DeleteItem(Object(DeleteItemType)) #2 {main}
thrown in C:\xampp\htdocs\test\wsdl2phpgenerator\xmltfhs\test.php on line 140
【问题讨论】:
-
您使用的是哪台服务器? apache、nginx 还是 iis?
-
阿帕奇。如果您能提供帮助将不胜感激。
-
这可能是文件权限问题吗?在每种情况下,您都可能以不同的用户身份运行脚本。尝试一个可用于 cookies.json 的 tmp 文件夹。
-
谢谢@Progrock 你的回答有帮助。
-
@Progrock 您可以添加答案。正如您在评论中提到的,我为 cookies.json 创建了一个文件夹并授予了世界写入文件权限,并且它起作用了。
标签: php curl soap exchange-server exchangewebservices