我想在我的C代码中读取一个八位字节流。输出示例(它的docker API日志输出):
HTTP/1.0 200 OK
Date: Wed, 13 May 2015 20:09:13 GMT
Content-Type: application/octet-stream
▒2015-05-13T20:09:06.335126685Z 2015-05-13 20:09:06 ERROR AppException: <traceback>
我的代码:
char *message = NULL;
char buffer[buffer_size+1];
while ((nbytes = read(sock, buffer, buffer_size)) > 0 )
{
buffer[nbytes] = 0;
message = realloc(message, (strlen(message) + nbytes + 1));
strcat(message, buffer);
}
log(LOG_LEVEL_DEBUG, "message: %s", message);
但是我只能读取标题(消息变量的调试输出):
▒w▒WHTTP/1.0 200 OK
Date: Wed, 13 May 2015 20:14:41 GMT
Content-Type: application/octet-stream
如何阅读回复内容? 响应中的非ASCII字符是否可以成为问题? 另一个Docker API响应(inspect,info,ps)没有这个问题。