Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. $data = ['data' => 'this', 'data2' => 'that'];
  2. $headers = [
  3. 'Accept' => '*/*',
  4. 'Content-Type' => 'application/x-www-form-urlencoded',
  5. 'Custom-Header' => 'custom-value',
  6. 'Custom-Header-Two' => 'custom-value',
  7. ];
  8. // open connection
  9. $ch = curl_init();
  10.  
  11. // set curl options
  12. $options = [
  13. CURLOPT_URL => $url,
  14. CURLOPT_POST => count($data),
  15. CURLOPT_POSTFIELDS => http_build_query($data),
  16. CURLOPT_HTTPHEADER => $headers,
  17. CURLOPT_RETURNTRANSFER => true,
  18. CURLOPT_FOLLOWLOCATION => false //Sets follow_location to false so the header will be inserted
  19. ];
  20. curl_setopt_array($ch, $options);
  21.  
  22. // execute
  23. $result = curl_exec($ch);
  24.  
  25. // close connection
  26. curl_close($ch);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement