user5362206
user5362206

Reputation:

socket, request http webpage

I am fetching some websites with sockets by making a http request and reading the response header like this:

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

This is the receive function:

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;
    }
}

And this part of the response im getting:

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>

As you can see, im getting this characters '3b19' at the end of the response header, what is that? Its a different set of characters every single time and I can't seem to find them at: http://www.stackoverflow.com/questions/12691882/how-to-send-and-receive-data-socket-tcp-c-c which is the page that im fetching.

Upvotes: 0

Views: 178

Answers (1)

MikeCAT
MikeCAT

Reputation: 75062

It is a length of the content send used in "chunked encoding".

RFC2616 3.6.1 Chunked Transfer Coding is describing about "chunked encoding".

Upvotes: 6

Related Questions