0

I am doing an HTTP post to a url to retrieve the contents of a file using php and curl as follows:

    $url = SITE_URL . 'filename.html';
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_POST, TRUE);
    curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);
    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3');
    $content = curl_exec($curl);
    $cerr = curl_error($curl);
    $info = curl_getinfo($curl);
    curl_close($curl);

This was working fine on one server, but when I moved to a new server it was blocked by ModSec rule 390616 - "Post request must have a content length header". As a quick fix I have had that rule white-listed, but I would prefer not to have to do that. So how do I add a content length header to the above code please?

panda
  • 821
  • 1
  • 9
  • 20

1 Answers1

0

You need to pass the Content-Length to CURLOPT_HTTPHEADER. It seems like you aren't sending any content, so Content-Length would be 0. So:

curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    "Content-Length: 0"
));
ishegg
  • 9,685
  • 3
  • 16
  • 31