C# HTTP 请求解析器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/975308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# HTTP Request Parser
提问by Gordon Thompson
Possible Duplicate:
Converting Raw HTTP Request into HTTPWebRequest Object
I've got a custom HTTP server written in C# which gives me the raw HTTP request...
我有一个用 C# 编写的自定义 HTTP 服务器,它给了我原始的 HTTP 请求......
GET /ACTION=TEST HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-gb,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive
Is there something in the .NET framework that I can use to parse it or do I have to do it by hand?
.NET 框架中有什么东西可以用来解析它还是我必须手动解析它?
Cheers
干杯
采纳答案by NicolasP
回答by Charles
Check out HttpMachine- a component of the KayakHTTP server for dotNET. HttpMachine is a callback driven HTTP parser.
查看HttpMachine-用于 dotNET的KayakHTTP 服务器的组件。HttpMachine 是一个回调驱动的 HTTP 解析器。
To wet your appetite, here's the IHttpParserHandlerinterface:
为了满足你的胃口,这里是IHttpParserHandler接口:
using System
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HttpMachine
{
public interface IHttpParserHandler
{
void OnMessageBegin(HttpParser parser);
void OnMethod(HttpParser parser, string method);
void OnRequestUri(HttpParser parser, string requestUri);
void OnFragment(HttpParser parser, string fragment);
void OnQueryString(HttpParser parser, string queryString);
void OnHeaderName(HttpParser parser, string name);
void OnHeaderValue(HttpParser parser, string value);
void OnHeadersEnd(HttpParser parser);
void OnBody(HttpParser parser, ArraySegment<byte> data);
void OnMessageEnd(HttpParser parser);
}
}