I am trying to get a server side POST to work in PHP. I am trying to send transaction data to a payment gateway but I keep getting the following error:
Message:
fopen(https://secure.ogone.com/ncol/test/orderstandard.asp): failed to open stream: HTTP request failed! HTTP/1.1 411 Length Required
Code:
$opts = array(
'http' => array(
'Content-Type: text/html; charset=utf-8',
'method' => "POST",
'header' => "Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
$fp = fopen('https://secure.ogone.com/ncol/test/orderstandard.asp', 'r', false, $context);
fpassthru($fp);
fclose($fp);
Tried a few solutions found online – mostly shots in the dark so no luck so far!
Just add content length. Once you actually start sending content you’ll need to calculate its length.