套接字,请求HTTP网页



我通过发出http请求并读取响应头来获取一些带有套接字的网站:

char buffer[1000];
while ((bytesReceived = tcpSocket.Receive(buffer, 1000-1)) > 0)
{
    buffer[bytesReceived] = '';
    myFile << buffer;
    memset(buffer, 0, 1000);
}

这是接收函数:

int fsx::TcpSocket::Receive(char* _buffer, size_t _length)
{
    int iResult = recv(this->socketHandler, _buffer, _length, 0);
    if (iResult >= 0)
    {
        return iResult;
    }
    else
    {
        return SOCKET_ERROR;
    }
}

和我得到的这部分回应:

HTTP/1.1 200 OK
Date: Tue, 22 Sep 2015 10:46:10 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: close
Set-Cookie: __cfduid=d01e9db42c5332c444d5105c2cd9fd9e01442918769; expires=Wed, 21-Sep-16 10:46:09 GMT; path=/; domain=.stackoverflow.com; HttpOnly
Cache-Control: public, no-cache="Set-Cookie", max-age=60
Cf-Railgun: 2b57bd3274 5.38 0.314316 0030 3350
Expires: Tue, 22 Sep 2015 10:47:09 GMT
Last-Modified: Tue, 22 Sep 2015 10:46:09 GMT
Vary: *
X-Frame-Options: SAMEORIGIN
X-Request-Guid: 9921fd42-6fd5-4a34-a839-c87d26b2f39a
Set-Cookie: prov=e6796729-38a7-4754-af17-96349ae78010; domain=.stackoverflow.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
Server: cloudflare-nginx
CF-RAY: 229d6ca79fef05b5-ARN
3b19 //<------------- WHAT THE HECK IS THIS?
<!DOCTYPE html>
<html itemscope itemtype="http://schema.org/QAPage">
<head>

正如你所看到的,我在响应头的末尾得到了这个字符'3b19',这是什么?每次都是一组不同的字符,我似乎找不到它们:http://www.stackoverflow.com/questions/12691882/how-to-send-and-receive-data-socket-tcp-c-c,这是我取的页面。

在"分块编码"中使用的内容长度。

RFC2616 3.6.1分块传输编码描述了"分块编码"。

最新更新