在C ++中将HTTP响应主体与标题分隔开 [英] Separating HTTP Response Body from Header in C++

查看:119
本文介绍了在C ++中将HTTP响应主体与标题分隔开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前为某个项目编写我自己的C ++ HTTP类。我试图找到一种方法来分隔响应主体和标题,因为这是我需要返回的唯一部分。

I'm currently writing my own C++ HTTP class for a certain project. And I'm trying to find a way to separate the response body from the header, because that's the only part I need to return.

这里是一个原始http如果您不熟悉它:

Here's a sample of the raw http headers if you're not familiar with it:

HTTP/1.1 200 OK
Server: nginx/0.7.65
Date: Wed, 29 Dec 2010 06:13:07 GMT
Content-Type: text
Connection: keep-alive
Vary: Cookie
Content-Length: 82

下面是HTML /响应正文。什么是最好的方法做到这一点?我只是使用Winsock库的请求的方式(我甚至不认为这很重要)。

Below that is the HTML/Response body. What would be the best way to do this? I'm only using Winsock library for the requests by the way (I don't even think this matters).

提前感谢。

推荐答案

HTTP标头由序列 \r\\\
\r\\\
(空白线)。只是搜索,并返回一切后。 (它可能不存在,例如,如果它是响应 HEAD 请求。)

HTTP headers are terminated by the sequence \r\n\r\n (a blank line). Just search for that, and return everything after. (It may not exist of course, e.g. if it was in response to a HEAD request.)

这篇关于在C ++中将HTTP响应主体与标题分隔开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆