How to call other url using curl in php..?

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

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.

   $postData = array(
   'user' => 'admin',
   'pw' => 'admin',
   'submit' => 'Login'

  // Setup cURL
  $ch = curl_init('');
  curl_setopt_array($ch, array(
  CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form-urlencoded'
  CURLOPT_POSTFIELDS => json_encode($postData)

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


 // Check for errors
  if($response === FALSE){

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

// Print the date from the response
 echo $responseData['published'];

Is it possible there’s something about the way you are calling the URL that is causing it to redirect to a 440 page? That is, the page isn’t actually missing, just that you’re not providing the correct login details and, rather than giving a specific message, the failed logon is just sending you to the generic error page?

@droopsnoot…i’m sending data in the same manner as im sending in postman app…
Below is my postman response

What about sid listed in that screen-shot, but not in your code?

And in your code you send ‘x-www-form-urlencoded’, but in the screen shot you have ticked ‘form-data’.

@droopsnoot…Sid is empty… When i tried to insert in the postData array in my code… It showed some error…

If “sid” is SESSION id, then I think you’re going to need to use a valid value for that or change the code in the handle_login.tcl file to deal with the curl request.

@Mittineague… Sid is retrieved once my request hit the website ive mentioned… With the session id i get as response i need to print…

I must be not understanding something. What is the

1 Like

@Mittineague…sid means session id and whole point of my code is to retrieve the session id from the url ive mentioned and print it…

I’ve rectified the mistake commited in the code and posting the answer below…

         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL,"URL");
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS,
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        // Send the request 
         $response = curl_exec($ch);
         curl_close ($ch);
         echo "$response";
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.