веб-сервисы — не в состоянии сделать вызов API, используя php CURL

Это формат запроса SOAP-запроса.

<SOAP-ENV:Envelopexmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sas="http://api.testdemo.in/">

<SOAP-ENV:Body>

<sas:Login>

<Username>user</Username>

<Password>password</Password>

</sas:Login>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

Я попробовал следующие коды ниже,

$xml = '<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"xmlns:sas="http://api.testdemo.in/">
<SOAP-ENV:Body>
<sas:Login>
<Username>user</Username>
<Password>password</Password>
</sas:Login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>';

$url = "http://api.testdemo.in/";

$ch = curl_init();
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");
if($xml != null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml");
array_push($headers, "Content-Length: " . strlen($xml));
}
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);

$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
print_r($response);
print_r($code);

Эта страница загружена некоторое время, и я получил ‘0’ на странице.

Фактический ответ XML должен быть

<SOAP-ENV:Envelopexmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sas="http://api.testdemo.in/">

<SOAP-ENV:Body>

<sas:LoginResponse>

<SessionID>FC82329EF6</SessionID>

<ResponseCode>0</ResponseCode>

<ResponseMessage>Successsful</ResponseMessage>

</sas:LoginResponse>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

Я новичок в SOAP, не могу найти лучший способ … Я получил приведенный выше код в Интернете, я не знаю, как именно так должен выполняться запрос SOAP.

Пожалуйста, предложите несколько способов сделать это. Спасибо, ребята

0

Решение

Что вы хотели бы сделать, это проверить, есть ли ошибка скручивания, добавив ее после выполнения скручивания

try
{
$response = curl_exec($ch);

if(curl_errno($ch) == "0")    //check if there is an curl error occurred such as unable to connect to host etc
{
//do your parsing here

}
else
{
throw new exception('Curl Error No'.curl_errno($ch).' Error Description:'.curl_error($ch));
}
}
catch(Exception $e)
{
echo $e->getMessage();
}

С этого момента определите, является ли это ошибкой скручивания. Если это так, опубликуйте ошибку.

0

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

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

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