Guest User

Untitled

a guest
Apr 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. $server='http://188.17.157.70:82/test3/hs/';//test
  2.  
  3. //PHP
  4. $ch = curl_init();//инициализируем
  5. $data = json_encode($array,JSON_UNESCAPED_UNICODE);//данные
  6. curl_setopt($ch, CURLOPT_URL, $url_1c);//адрес
  7. curl_setopt($ch, CURLOPT_POST, 1);//?
  8. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//?
  9. $result = curl_exec($ch);//посылаем, и получаем ответ
  10. curl_close($ch);//закрываем соединение
  11.  
  12. //смотрим что в ответе
  13. echo '<pre>['; print_r($result); echo ']</pre>';
  14.  
  15. //вариант 1, ошибка ( все пошло не так )
  16. Ошибка инициализации модуля: НазваниеМодуль..[]
  17.  
  18. //вариант 2, все норм, как бы ( возвращается 2 ответа, т.е. 2 json )
  19. {"status":"ok","data":["key1":"val1","key2":"val2"]}[]{"status":"true"}
  20.  
  21. function isJson($string) {
  22. return ((is_string($string) &&
  23. (is_object(json_decode($string)) ||
  24. is_array(json_decode($string))))) ? true : false;
  25. }
  26.  
  27. if (isJson($result)) {
  28. // Все ОК
  29. } else {
  30. // Ошибка
  31. }
Add Comment
Please, Sign In to add comment