ClarkeRubber

php curl json post

Feb 1st, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.49 KB | None | 0 0
  1.     if ( !empty( $problems ) ) {
  2.  
  3.         $json = json_encode( $problems );
  4.  
  5.         $url = 'http://en.lichess.org/api/problem?token=';
  6.  
  7.         $ch = curl_init( $url );
  8.         curl_setopt( $ch, CURLOPT_POST, 1 );
  9.         curl_setopt( $ch, CURLOPT_POSTFIELDS, $json );
  10.         curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
  11.         curl_setopt( $ch, CURLOPT_HEADER, 0 );
  12.         curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
  13.  
  14.         $response = curl_exec( $ch );
  15.  
  16.         print_r( $response );
  17.  
  18.         return $json;
  19.  
  20.     } else {
  21.  
  22.         exit( 1 );
  23.  
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment