Skip to content
This repository has been archived by the owner on Sep 29, 2022. It is now read-only.

HttpRequest构造函数在获取Request Body时进入死循环 #30

Open
xmyhhh opened this issue Dec 6, 2019 · 1 comment
Open

HttpRequest构造函数在获取Request Body时进入死循环 #30

xmyhhh opened this issue Dec 6, 2019 · 1 comment

Comments

@xmyhhh
Copy link

xmyhhh commented Dec 6, 2019

        if (int.TryParse(contentLength, out var length) && Body.Length != length)
        {
            do
            {
                length = stream.Read(bytes, 0, MAX_SIZE - 1);
                Body += Encoding.UTF8.GetString(bytes, 0, length);
            } while (Body.Length != length);
        }

这段代中的while循环跳出不来,如果MAX_SIZE很大,则 length始终为0;如果MAX_SIZE很大,则 Body.Length 始终大于 length。

当我用multipart/form-data POST 上传图片时发生

@dualxu
Copy link

dualxu commented May 18, 2021

我也发现这个问题了,搞了2天。

我修改了,分享下:
//Request Body
Body = GetRequestBody(rows);
var contentLength = GetHeader(RequestHeaders.ContentLength);
int length = 0;
int totallen = 0;
if (int.TryParse(contentLength, out totallen) && (Body.Length != totallen))
{
do
{
length = stream.Read(bytes, 0, MAX_SIZE - 1);
Body += Encoding.UTF8.GetString(bytes, 0, length);
} while (Body.Length != totallen);
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants