Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. $ch = curl_init();
  2. curl_setopt_array($ch, [
  3. CURLOPT_URL => $url,
  4. CURLOPT_TIMEOUT_MS => 500,
  5. CURLOPT_RETURNTRANSFER => true,
  6. CURLOPT_POST => true,
  7. CURLOPT_POSTFIELDS => json_encode($data),
  8. CURLOPT_HTTPHEADER => [
  9. 'X-Requested-With: XMLHttpRequest',
  10. 'Content-Type: application/json',
  11. 'Accept: application/json'
  12. ],
  13. CURLOPT_NOSIGNAL =>1;
  14. ]);
  15. $response = curl_exec($ch);
  16. $curl_errno = curl_errno($ch);
  17. $curl_err = curl_error($ch);
  18. $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  19. curl_close($ch);
  20. if ($http_code != 200) {
  21. log_message('error', 'curl error;curl_errno=' . $curl_errno . ';curl_err=' . $curl_err);
  22. } elseif (!$result = json_decode($response, true)) {
  23. log_message('error', 'decode_errno=' . json_last_error() . ';decode_error=' . json_last_error_msg() . ';response=' .$response);
  24. }
  25. ......
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement