openssl bio_read是错误的

发布于 2025-01-26 14:18:01 字数 1517 浏览 3 评论 0原文

这是我如何阅读HTTPS请求的响应的代码:

int len = 0;
f = fopen("response.txt", "wb");
do
{
    char buff[1534];
    len = BIO_read(bio, buff, sizeof(buff));

    if (len > 0) {
        fwrite(buff, sizeof(char), len, f);
    }

} while (len > 0 || BIO_should_retry(bio));
fclose(f);

响应应该是“最小化” JSON(无新行),但是无论出于何种原因,我都看到一些“随机”插入的\ r \ n如果我使用十六进制编辑器查看响应:

image

33333333333333333333。 35 2C 2D 31 35 0D 0A 31 31 30 30 30 0D 0A

这是JSON数组的摘录,因此,代替\ r \ n应该只有一个

此外,http响应主体在实际的json之前包含一些奇怪的字符:

image

HTTP/1.1 201 Created
Server: nginx/1.21.3
Date: Wed, 04 May 2022 11:22:22 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: close
Location: http://myserver.de/my/endpoint
api-supported-versions: 1.0

1f1b

inbete 只有数字)有三个不应该存在的字符:

image

和在JSON之后,还有一个不应该存在的0:

image

<代码> 0 。

我能想到的唯一原因是违反记忆约束。

除了上述错误外,返回的JSON是正确的,并且后端对请求没有任何问题,因此我认为这是正确的。

有什么想法我如何解决这个问题?

This is the code how I am reading the response from my HTTPS request:

int len = 0;
f = fopen("response.txt", "wb");
do
{
    char buff[1534];
    len = BIO_read(bio, buff, sizeof(buff));

    if (len > 0) {
        fwrite(buff, sizeof(char), len, f);
    }

} while (len > 0 || BIO_should_retry(bio));
fclose(f);

The response should be a "minimized" JSON (no new lines), but for whatever reason, I am seeing some "randomly" inserted \r\n if I look at the response with a HEX editor:

Image

33 35 2C 2D 31 31 35 0D 0A 31 30 30 30 0D 0A

This is an excerpt from a JSON array, so instead of \r\n there should be just a ,.

Also the HTTP response body contains some weird characters before the actual JSON:

Image

HTTP/1.1 201 Created
Server: nginx/1.21.3
Date: Wed, 04 May 2022 11:22:22 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: close
Location: http://myserver.de/my/endpoint
api-supported-versions: 1.0

1f1b

Inbetween a JSON array (with just numbers) there are three characters which shouldn't be there:

Image

ead

And after the JSON there is an additional 0 which shouldn't be there:

Image

0.

The only reason I can think about is some memory constraint violation.

The returned JSON is correct besides the mentioned errors and the backend doesn't have any issues with the request so I assume that it is correct.

Any ideas how I can fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始于初秋 2025-02-02 14:18:01

之所以发生这种情况,是因为我的请求具有http/1.1,

POST /my/endpoint HTTP/1.1
Host: localhost
Content-Type: multipart/form-data; boundary=123456
Content-Length: 83031
Connection: close

如果将其更改为http/1.0,则工件消失了。

This happend because my request had HTTP/1.1

POST /my/endpoint HTTP/1.1
Host: localhost
Content-Type: multipart/form-data; boundary=123456
Content-Length: 83031
Connection: close

if I change it to HTTP/1.0, the artifacts disappear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文