-3

when i hit the following url with the postman app its working fine

http://192.168.1.220/cgi-bin/handle_login.tcl

but when tried with curl its giving me following error

    The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

Below is my php code

    <?php
   $postData = array(
   'user' => 'admin',
   'pw' => 'admin',
   'submit' => 'Login'
   );

  // Setup cURL
  $ch = curl_init('http://192.168.1.220/cgi-bin/handle_login.tcl');
  curl_setopt_array($ch, array(
  CURLOPT_POST => TRUE,
  CURLOPT_RETURNTRANSFER => TRUE,
  CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form-urlencoded'
 ),
  CURLOPT_POSTFIELDS => json_encode($postData)
));

 // Send the request
   $response = curl_exec($ch);

 var_dump($response);

 // Check for errors
  if($response === FALSE){
  die(curl_error($ch));
  }

   // Decode the response
    $responseData = json_decode($response, TRUE);

// Print the date from the response
 echo $responseData['published'];
 ?>
Pradeep
  • 267
  • 4
  • 15
  • 1
    You seem to be severely mistaken on how Stack Overflow works. Please check the [help], mainly [ask] and [Be Nice](http://stackoverflow.com/help/be-nice). – Kyll May 19 '17 at 10:27
  • @Nitish..u think im posting questions for upvote ....in one of previous questions a user willinggly downvoted and posted some irrelevent answer and asked me for green tick and upvote...and im not doing that..ive facing error nd ive posted what ive got...if u want to help me just notify me the mistake ive done... – Pradeep May 19 '17 at 11:02
  • Lol... @Nitish....i think uve been going thru my post.... I think for that post ive posted the answer by myself..... – Pradeep May 19 '17 at 12:07

1 Answers1

0

I've rectified the error in my code and I got desired answer...

Below is the answer

    $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL,"URL");
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS,
    "key1=value1&key2=value2&key3=value3");         
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Send the request 
     $response = curl_exec($ch);
     curl_close ($ch);
     echo "$response";
Pradeep
  • 267
  • 4
  • 15