如何解析来自一个基于C的Web服务器的HTTP请求 [英] How to parse HTTP requests from a C based web server

查看:482
本文介绍了如何解析来自一个基于C的Web服务器的HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个编程项目中,我要创建一个处理HTTP请求多线程Web服务器。

I have a programming project where I have to create a multithreaded web server which handles HTTP requests.

我刚刚学到socket编程,我得到了一个客户端和服务器上运行。我想知道的最好的方法是什么解析HTTP请求头。我看到这个:如何解析在C http请求++ 的几分钟背部。但我宁愿不转移到C ++在这一点上。因此,人们应该如何去用C解析HTTP请求?

I just learned socket programming and I got a client and a server running. I wanted to know what the best method would be for parsing the HTTP request headers. I saw this: how to parse http request in c++ a few minutes back. But I would rather not shift to C++ at this point. So how should one go about parsing an HTTP request in C?

推荐答案

您可以看看在C网络服务器,如猫鼬(的 https://github.com/cesanta/mongoose/blob/master/mongoose.c ),可以使用同样的方法来分析该HTTP请求。但我建议是,仅仅经过HTTP RFC 2616,因为这将帮助你在写自己的解析器HTTP请求。​​

You can have a look at the web servers in C such as mongoose (https://github.com/cesanta/mongoose/blob/master/mongoose.c) and could use the same methodology to parse the http request. But what would I suggest is that just go through the HTTP RFC 2616 since that would help you in writing your own parser for http requests.

通过何种HTTP请求的服务器的处理是(GET或POST或两者)??的方式

By the way which kind of HTTP requests your Server is handling (GET or POST or BOTH) ??

在HTTP POST请求的HTTP标头和放大器;数据由\\ r \\ n \\ r \\ n分隔。
在sscanf的内容长度接收到的数据形成的HTTP头然后开始读取数据后,你会得到\\ r \\ n \\ r \\ n,直到你在内容长度提到的数据是相同的。

In http post requests the HTTP header & data are separated by "\r\n\r\n". In received data sscanf the Content-Length form the http header then start reading the data after you get "\r\n\r\n" until you get the same amount of data as mentioned in Content-Length.

这篇关于如何解析来自一个基于C的Web服务器的HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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