curl — запрос PHP Soap работает в cli, но не в браузере

Мы делаем запрос на мыло на сервер Microsoft Exchange Exchange 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

2

Решение

Это было связано с проблемой разрешения файла. Я добавил файл cookies.json в папку tmp, дал ему разрешение на запись во всем мире и изменил путь cookies.json в классе SoapClient.

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector