PHP服务器端帖子 [英] PHP server side post

查看:61
本文介绍了PHP服务器端帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让服务器端 POST 在 PHP 中工作.我正在尝试将交易数据发送到支付网关,但我不断收到以下错误:

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:

消息:fopen(https://secure.ogone.com/ncol/test/orderstandard.asp):无法打开流:HTTP 请求失败!HTTP/1.1 411 长度要求

Message: fopen(https://secure.ogone.com/ncol/test/orderstandard.asp): failed to open stream: HTTP request failed! HTTP/1.1 411 Length Required

代码:

$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.

$data = "";
$opts = array(
    'http' => array(
        'Content-Type: text/html; charset=utf-8',
        'method' => "POST",
        'header' => "Accept-language: en\r\n" .
        "Cookie: foo=bar\r\n" .
        'Content-length: '. strlen($data) . "\r\n",
        'content' => $data
     )
);

$context = stream_context_create($opts);

$fp = fopen('https://secure.ogone.com/ncol/test/orderstandard.asp', 'r', false, $context);
fpassthru($fp);
fclose($fp);

这篇关于PHP服务器端帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆