1

您好,我目前正在整合商家帐户系统。

我需要将 http 请求中的总字节数发送到我网站上的 url。我的网站是用 PHP 编写的。

在 C# 中,它的工作方式如下:但要提到的主要一点是我将如何在 PH 中执行此操作,因为似乎无法找到关于此的良好文档。提前致谢

 public void ProcessRequest (HttpContext context) 
{
    context.Response.Buffer = true;

    string response = "";
    string sMethod = "POST";

    //sUrl holds the address to the Verify service, this is a service from AllCharge 
    // that verifies the signature on the notification. This makes sure that the notification
    // was sent by AllCharge.

    //Demo server - use this address during the integaration, remark this line when working
    // with the live server
    string sUrl = "http://demo.allcharge.com/Verify/VerifyNotification.aspx";

    //Live server - use this address when working with the live server, remark this line 
    // during the integration
    //string sUrl = "https://incharge.allcharge.com/Verify/VerifyNotification.aspx";

    Int32 nCount = context.Request.TotalBytes;
    string formParameters = System.Text.Encoding.UTF8.GetString(context.Request.BinaryRead(nCount));

}
4

5 回答 5

1

我能想到的最好的就是下面的 php 函数。

function findKb($content){
$count=0;
$order = array("\r\n", "\n", "\r", "chr(13)",  "\t", "\0", "\x0B");
$content = str_replace($order, "12", $content);
for ($index = 0; $index < strlen($content); $index ++){
    $byte = ord($content[$index]);
    if ($byte <= 127) { $count++; }
    else if ($byte >= 194 && $byte <= 223) { $count=$count+2; }
    else if ($byte >= 224 && $byte <= 239) { $count=$count+3; }
    else if ($byte >= 240 && $byte <= 244) { $count=$count+4; }
}
return $count;
}
于 2012-09-13T14:21:24.807 回答
1

试试这个:

$rqsize = (int) $_SERVER['CONTENT_LENGTH'];

类似的事情已经在这里问过了。

于 2012-09-13T14:21:36.580 回答
1
$size = intval($_SERVER['CONTENT_LENGTH']);

$size应该是请求的长度。

于 2012-09-13T14:21:49.233 回答
1

PHP 是解释语言,很难做到这一点,尝试使用memory_get_usage函数,这里是示例http://it.php.net/manual/en/function.memory-get-usage.php

于 2012-09-13T14:36:04.300 回答
0

我发现让我使用它的最佳方法是使用:

$size = @file_get_contents('php://input');

谢谢你们的帮助!

于 2012-09-13T15:43:33.030 回答