openssl bio_read是错误的
这是我如何阅读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
如果我使用十六进制编辑器查看响应:
33333333333333333333。 35 2C 2D 31 35 0D 0A 31 31 30 30 30 0D 0A
这是JSON数组的摘录,因此,代替\ r \ n
应该只有一个,
。
此外,http响应主体在实际的json之前包含一些奇怪的字符:
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 只有数字)有三个不应该存在的字符:
和在JSON之后,还有一个不应该存在的0:
<代码> 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:
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:
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:
ead
And after the JSON there is an additional 0 which shouldn't be there:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
之所以发生这种情况,是因为我的请求具有http/1.1,
如果将其更改为
http/1.0
,则工件消失了。This happend because my request had HTTP/1.1
if I change it to
HTTP/1.0
, the artifacts disappear.