как реализовать запрос мыла в php? - PullRequest
0 голосов
/ 03 октября 2018

Я искал на этом сайте полезный ответ для интеграции SOAP-запроса в PHP, но не нашел ничего, что решило бы мою проблему.

Я новичок в SOAP и не могу понять, почемуЯ не получаю никакого ответа:

 <?php
$xml = '<?xml version="1.0" encoding="utf-8"?>'.
    '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
    ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"'.
    ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'.
        '<soap:Body>'.
            '<food xmlns="http://www.localhost:81/dbWIP/xml1.xml">'.
                '<price>$5.95</price>'.
            '</food>'.
        '</soap:Body>'.
    '</soap:Envelope>';

$url = "http://www.localhost:81/dbWIP/xml1.xml";

$ch = curl_init();
echo $ch;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

$headers = array();
array_push($headers, "Content-Type: text/xml; charset=utf-8");
array_push($headers, "Accept: text/xml");
array_push($headers, "Cache-Control: no-cache");
array_push($headers, "Pragma: no-cache");
array_push($headers, "SOAPAction:http://www.localhost:81/dbWIP/xml1.xml");
if($xml != null) {
    echo $xml;
    curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml");
    array_push($headers, "Content-Length: " . strlen($xml));
}
curl_setopt($ch, CURLOPT_USERPWD, "user_name:password"); /* If required */
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
echo $response;
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo"<br/> CODE:"$code;
curl_close($ch);
?>

Ответы [ 2 ]

0 голосов
/ 03 октября 2018

Попробуйте убрать кавычки:

curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
0 голосов
/ 03 октября 2018

Я думаю, что вам не хватает URL из curl_init, который инициализирует сеанс cURL, но у вас нет URL.

    $curl = curl_init("http://www.localhost:81/dbWIP/xml1.xml");
    curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
    //curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
    //curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($curl);

И попробуйте установить заголовки на

   $headers = array(
        'Content-type: text/xml;charset="utf-8"',
        'Accept: text/xml',
        'Cache-Control: no-cache',
        'Pragma: no-cache',
        'Content-length: ' . strlen($xml),
    );
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...