简体   繁体   中英

how to use curl request json to login to remote site

I had done this:

 <?php 
       $post_body = '{"login": "injoit", "password": "injoit"}';
       $cookie_file = tempnam('/temp', 'cookie');
       $ch = curl_init('remote server login here');

       curl_setopt($ch, CURLOPT_HEADER, 0);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt($ch, CURLOPT_POST, 1);
       curl_setopt($ch, CURLOPT_POSTFIELDS, $post_body);
       curl_exec($ch);

I am getting this in response : Failed to connect to "remote server url here" port 8002: Connection timed out(7)

try

   $cookie_file = tempnam('./temp', 'cookie');
   $post_fields = '{"login": "injoit", "password": "injoit"}';
   $ch = curl_init('http://api.quickblox.com/login.json');
   curl_setopt($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
   curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
   curl_exec($ch);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM