gpt4 book ai didi

php http请求向正文添加随机十六进制代码

转载 作者:可可西里 更新时间:2023-11-01 16:43:36 25 4
gpt4 key购买 nike

我的网络系统上有一个 CSV 导出文件,我正试图从客户端查询它。我从来没有遇到过任何问题,但出于某种原因,对于我的一位客户,返回的数据在主体之前有一个额外的 4 个字符,我无法弄清楚它来自哪里!

HTTP/1.1 200 OK
Date: Mon, 17 Jun 2013 09:17:22 GMT
Server: Apache/2.2
Set-Cookie: username=xxx expires=Mon, 17-Jun-2013 11:17:22 GMT; path=/
Set-Cookie: password=xxx; expires=Mon, 17-Jun-2013 11:17:22 GMT; path=/
Content-Disposition: attachment; filename="xxx-Stock.csv"
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/csv

20b1
"code","dsc","cat","sub","whqc","qty"
..................

在上面,20b1 在我 body 之前。我已经通过相同的方式手动下载了文件,但在文件中看不到它。

The export code looks like:
header("Content-Disposition: attachment; filename=\"" . $file . "\"");
header("Content-type: text/csv");
$tmp["header"] = "\"code\",";
$tmp["header"].= "\"dsc\",";
$tmp["header"].= "\"cat\",";
$tmp["header"].= "\"sub\",";
$tmp["header"].= "\"whqc\",";
$tmp["header"].= "\"qty\"\n";
echo $tmp["header"];

for ($i = 1; $i <= $data["count"]; $i++ ) {
$j = 1;
while ( isset($data[$i][$j]) ) {
$tmp["line"] = "\"" . str_replace("\"", "\"\"", $data[$i]["code"]) . "\",";
$tmp["line"].= "\"" . str_replace("\"", "\"\"", $data[$i]["full_name"]) . "\",";
$tmp["line"].= "\"" . str_replace("\"", "\"\"", $data[$i]["prstkcat"]) . "\",";
$tmp["line"].= "\"" . str_replace("\"", "\"\"", $data[$i]["prsubcat"]) . "\",";
$tmp["line"].= "\"" . str_replace("\"", "\"\"", $data[$i][$j]["whqc"]) . "\",";
$tmp["line"].= "\"" . str_replace("\"", "\"\"", $data[$i][$j]["qty"]) . "\"\n";
echo $tmp["line"];
$j++;
}
}

奇怪的是,我的其他客户并没有发生这种情况,所以我想也许来自这个客户的数据有些奇怪。如果我注释掉一些 $tmp["line"],它不会显示。其他时候,如果我注释掉其中一行,这段代码就会改变。

到底是什么东西可以把这个角色放在那里?!

更新:它仅在服务器返回分块编码时执行此操作。我将代码更改为以下内容,现在可以使用了(希望得到解释,因为这不是我的专业领域!)。

header("Content-Disposition: attachment; filename=\"" . $file . "\"");
header("Content-type: text/csv");

$tmp["header"] = "\"code\",";
$tmp["header"].= "\"dsc\",";
$tmp["header"].= "\"cat\",";
$tmp["header"].= "\"sub\",";
$tmp["header"].= "\"whqc\",";
$tmp["header"].= "\"qty\"\n";
$tmp["line"] = "";
for ($i = 1; $i <= $data["count"]; $i++ ) {
$j = 1;
while ( isset($data[$i][$j]) ) {
$tmp["line"].= "\"" . str_replace("\"", "\"\"", $data[$i]["code"]) . "\",";
$tmp["line"].= "\"" . str_replace("\"", "\"\"", $data[$i]["full_name"]) . "\",";
$tmp["line"].= "\"" . str_replace("\"", "\"\"", $data[$i]["prstkcat"]) . "\",";
$tmp["line"].= "\"" . str_replace("\"", "\"\"", $data[$i]["prsubcat"]) . "\",";
$tmp["line"].= "\"" . str_replace("\"", "\"\"", $data[$i][$j]["whqc"]) . "\",";
$tmp["line"].= "\"" . str_replace("\"", "\"\"", $data[$i][$j]["qty"]) . "\"\n";
$j++;
}
}
header("Content-Length: " . strlen($tmp["header"] . $tmp["line"]));
echo $tmp["header"] . $tmp["line"];

最佳答案

去掉这个

echo $tmp["header"];

关于php http请求向正文添加随机十六进制代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17144201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com