C # HTTP Request Parser

Possible duplicate:
Convert the original HTTP request to an HTTPWebRequest object

I have a custom HTTP server written in C # that gives me a raw HTTP request ...

  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 need to do it manually?

Greetings

+4
source share
2 answers

It looks like this question has been asked before here . There seems to be no built-in way to do this.

+3
source

Check out HttpMachine - Kayak's HTTP server component for dotNET. HttpMachine is an HTTP parser with a callback.

To wet your appetite, here's the IHttpParserHandler interface:

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); } } 
+6
source

Source: https://habr.com/ru/post/1286008/


All Articles