如何从 C 中的 HTTP 标头中提取数据? [英] How to extract data from HTTP header in C?
本文介绍了如何从 C 中的 HTTP 标头中提取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
今天我在问如何在 C(不是 C++)中的 recv()
中从接收的缓冲区中提取数据部分.
Today I am asking how to extract the data section from the received buffer in my recv()
in C (not C++).
我只是需要一些建议,我将如何获得
I just need some suggestions, how would I get
HTTP/1.1 200 OK
Date: Mon, 23 May 2005 22:38:34 GMT
Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
ETag: "3f80f-1b6-3e1cb03b"
Content-Type: text/html; charset=UTF-8
Content-Length: 131
Connection: close
<html>
<head>
<title>An Example Page</title>
</head>
<body>
Hello World, this is a very simple HTML document.
</body>
</html>
上述标题的部分?它存储在我的缓冲区中,我只想剖析数据(页面的源代码).有什么想法吗?
The part of the above header? It is stored in my buffer, I specifically just want to dissect the data (the source code of the page). Any ideas?
推荐答案
header 以
结尾.如果整个响应都在接收缓冲区中,并且您在响应末尾放置了一个 ' '
,那么您可以使用以下代码找到数据部分的开头
The header ends with
. If the whole response is in the receive buffer and you put a ' '
at the end of the response, then you can use the following code to find the start of the data section
char *data = strstr( buffer, "
" );
if ( data != NULL )
{
data += 4;
// do something with the data
}
这篇关于如何从 C 中的 HTTP 标头中提取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文