CURL URL change after POST

I am doing HTTP POST using cURL

$url = "http://localhost:8080/~demo/cgi-bin/execute/100";

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($data));
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);

//execute post
$result = curl_exec($ch);
echo("$result");
//close connection
curl_close($ch);

The message starts, but the response is displayed with an error:

The requested URL / ~ demo / 100 was not found on this server .


The above URL obviously does not exist, and not because (somehow) cURL changed the URL.

It should be /~demo/cgi-bin/execute/100. This URL works in a browser.

Please tell me why this is so? And how can I stop it, what do I want?

+3
source share
4 answers
  • Install Fiddler.
  • Enable debugging.
  • Visit the site in a browser.
  • Run php cURL code.

Fiddler , -. , , php. , .

+2

, cURL HTTP 80?

curl_setopt($ch, CURLOPT_PORT, 8080)
+1

This may not be cURL, which changes the URL, but rather that the web server sends the redirect header to cURL, pointing to a different location. Perhaps the following will help:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
0
source

Where?

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
0
source

Source: https://habr.com/ru/post/1702566/


All Articles