Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: Web API
Форумы портала PHP.SU » » Вопросы новичков » Web API

Страниц (1): [1]
 

1. snikers987 - 21 Октября, 2011 - 20:35:29 - перейти к сообщению
Имеется
CODE (htmlphp):
скопировать код в буфер обмена
  1.  
  2. Запрос
  3.  
  4. POST /History/HistoryService.asmx HTTP/1.1
  5. Host: https://217.117.65.147:81
  6. Content-Type: text/xml; charset=utf-8
  7. Content-Length: length
  8. SOAPAction: "https://217.117.65.147:81/SaveMessage"
  9.  
  10. <?xml version="1.0" encoding="utf-8"?>
  11. <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/">
  12.  <soap:Body>
  13.    <SaveMessage xmlns="https://217.117.65.147:81/">
  14.      <type>string</type>
  15.      <client_name>string</client_name>
  16.      <mobilePhone>string</mobilePhone>
  17.      <comment>string</comment>
  18.      <id_manager>string</id_manager>
  19.      <referal>string</referal>
  20.      <sourceMessage>AGENTPORTAL-API</sourceMessage>
  21.      <request_id>string</request_id>
  22.    </SaveMessage>
  23.  </soap:Body>
  24. </soap:Envelope>
  25. HTTP/1.1 200 OK
  26. Content-Type: text/xml; charset=utf-8
  27. Content-Length: length
  28.  
  29. Ответ
  30.  
  31. <?xml version="1.0" encoding="utf-8"?>
  32. <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/">
  33.  <soap:Body>
  34.    <SaveMessageResponse xmlns="https://217.117.65.147:81/">
  35.      <SaveMessageResult>string</SaveMessageResult>
  36.    </SaveMessageResponse>
  37.  </soap:Body>
  38. </soap:Envelope>
  39.  


Подскажите, как этим пользоваться. Есть подозрения что с помощью CURL.
Или где можно почитать, спасибо.
2. White - 21 Октября, 2011 - 21:06:30 - перейти к сообщению
snikers987 Если не ошибаюсь - это REST, по нему достаточно много инфы в интернете, для php есть готовая библиотека https://github[dot]com/lux/phpactiveresource/wiki/
3. snikers987 - 22 Октября, 2011 - 16:46:48 - перейти к сообщению
PHP:
скопировать код в буфер обмена
  1. <?
  2.  
  3. $body =  "<?xml version=\"1.0\" encoding=\"utf-8\"?>
  4. <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/\">
  5. <soap:Body>
  6.   <SaveMessage xmlns=\"https://217.117.65.147:81/\">
  7.     <type>ccard</type>
  8.     <client_name>Name</client_name>
  9.     <mobilePhone>+38000000000</mobilePhone>
  10.     <comment>not call</comment>
  11.     <id_manager>00000000</id_manager>
  12.     <referal>http://site.info</referal>
  13.     <sourceMessage>PORTAL-API</sourceMessage>
  14.     <request_id>123458</request_id>
  15.   </SaveMessage>
  16. </soap:Body>
  17. </soap:Envelope>
  18. ";
  19. $curl_options = array (
  20.   CURLOPT_URL => 'https://217.117.65.147:81',
  21.   CURLOPT_POST => TRUE,
  22.   CURLOPT_SSL_VERIFYHOST => false,
  23.   CURLOPT_SSL_VERIFYPEER => false,
  24.   CURLOPT_HTTPHEADER => array(
  25.         "POST /History/HistoryService.asmx HTTP/1.1",
  26.         "Host: https://217.117.65.147:81",
  27.     "Content-Type: text/xml; charset=utf-8",
  28.     "Content-Length: " . strlen($body),
  29.     "SOAPAction: \"https://217.117.65.147:81/SaveMessage\""
  30.     ),
  31.   CURLOPT_POSTFIELDS => $body
  32.  );
  33. $curl = curl_init('https://217.117.65.147:81')
  34.   or die("cURL init error\n");
  35. curl_setopt_array($curl, $curl_options)
  36.   or die("cURL set options error\n" . curl_error($curl));
  37. $response = curl_exec($curl)
  38.   or die ("cURL execute eroor\n" . curl_error($curl));
  39. curl_close($curl);
  40.  
  41.  
  42. ?>


Получаю ошибку 400, уже мозг сломал..
4. snikers987 - 22 Октября, 2011 - 22:29:59 - перейти к сообщению
Как правильно отправить этот XML, ума не приложу, помогите..
5. snikers987 - 23 Октября, 2011 - 19:26:30 - перейти к сообщению
Собственно вопрос решен при помощи CURL. Спасибо откликнувшимся. Радость Радость Радость

 

Powered by ExBB FM 1.0 RC1