删除HTTP标题信息 [英] Remove HTTP Header Info

查看:132
本文介绍了删除HTTP标题信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C中,有一种方法可以在套接字上使用 recv()时排除数据附带的HTTP头信息。我试图读取一些二进制数据,我想要的只是实际的二进制信息,而不是HTTP头信息。收到的当前数据如下所示:

  HTTP / 1.1 200 OK 
Content-Length:3314
Content-Type:image / jpeg
Last-Modified:Tue,20 Mar 2012 14:51:34 GMT
Accept-Ranges:bytes
ETag:45da99f1a86cd1:6b9
服务器:Microsoft-IIS / 6.0
X-Powered-By:ASP.NET
日期:2012年8月20日星期一14:10:08 GMT
连接:关闭

╪α

我只想读取文件的二进制部分。 (这显然不是所有的二进制文件,只有那么多显示,因为我把我的recv循环的输出作为字符串打印出来,而第一个NULL字符在那个小的二进制字符串之后)。

我只需要摆脱标题部分,是否有一个简单的方法来做到这一点? 您需要提取 Content-Length 的值来知道要读取的二进制数据的大小,否则无法知道是否已收到所有数据。一个简单的方法来消费并且大部分忽略头部分,就是逐字节地读入传入的数据,直到\r\\\
\r\\\
,这表示标题部分的结束和内容的开始。


In C is there a way to exclude the HTTP header information that comes with the data when using recv() on a socket? I am trying to read some binary data and all I want is the actual binary information, not the HTTP header information. The current data received looks like this:

HTTP/1.1 200 OK
Content-Length: 3314
Content-Type: image/jpeg
Last-Modified: Tue, 20 Mar 2012 14:51:34 GMT
Accept-Ranges: bytes
ETag: "45da99f1a86cd1:6b9"
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Mon, 20 Aug 2012 14:10:08 GMT
Connection: close 

╪ α

I would like only to read the binary portion of the file. (That's obviously not all the binary, only that much was displayed since I printed the output from my recv loop as a string and the first NULL char is after that small binary string).

I just need to get rid of the header portion, is there a simple way to do this?

解决方案

I think you need to extract the value of the Content-Length to know the size of the binary data to be read otherwise it will be impossible to know whether all data has been received. A simple approach to consume, and mostly ignore, the header portion is to read the incoming data byte-by-byte until "\r\n\r\n" is encountered, which indicates the end of the header section and the beginning of the content.

这篇关于删除HTTP标题信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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