套接字,请求HTTP网页
socket, request http webpage
我通过发出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分块传输编码描述了"分块编码"。
相关文章:
- 如何在boost beast http请求中设置http头
- 在多个核心中处理一个HTTP请求
- SFML library: http request
- 使用 Winsock2.h C++向不和谐 API 发送 HTTP 请求时出现问题
- 在 emscripten 网页汇编正在运行期间更新进度条?
- 通过单独的 tcp 流建立 http 连接
- 如何使用QT创建器获取网页源代码?
- 使用 winsock 接收 http 请求
- 如何在 c++ 中通过 http 发送大型视频文件?
- 对于 http 请求,python 比 c++ 快吗?
- Qt 网页程序集缓存
- 使用 c++ 的 http 客户端的默认方法
- 如何使用C++和Boost Asio从HTTP发布请求中获取键值
- 如何使用boost/beast从HTTP POST请求中解析和提取有效负载?
- 如何重用 http::beast::flat_buffer 和 http::response?
- 在客户端和备忘录中获取 HTTP 命令
- 在C ++ ASIO中,如何为HTTP或HTTPS创建相同的套接字对象(接口/抽象问题?
- 如何在C++中获取重定向网页的URL
- 如何使用HTTP和Winsock加载网页
- 套接字,请求HTTP网页