I am having problems sending POST requests with my cURL script in PHP.
I am trying to make a proxy server, in fact, for personal use, which will receive a web page through the server and display it to me locally.
The URL is found as follows: http://fetch.example.com/http://theurl.com/
When I submit the form on this page, it will go to the ACTION form (with the extraction URL in front). I am trying to get it to process this POST request using the code below, but everything I get POST always results in a 400 Bad Request error.
$chpg = curl_init();
curl_setopt($chpg, CURLOPT_URL, $_URL);
curl_setopt($chpg, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($chpg, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($chpg, CURLOPT_COOKIESESSION, true);
curl_setopt($chpg, CURLOPT_COOKIEJAR, "cookies/$_COOKIE_FILE.$_DOMAIN.txt");
curl_setopt($chpg, CURLOPT_COOKIEFILE, "cookies/$_COOKIE_FILE.$_DOMAIN.txt");
if($_POST) {
$fields = array();
foreach($_POST as $col => $val) {
$fields[$col] = urlencode($val);
}
print_r($fields);
curl_setopt($chpg, CURLOPT_POST, count($fields));
curl_setopt($chpg, CURLOPT_POSTDATA, $fields);
}
source
share