简体   繁体   English

在C#中解析原始HTTP-还是更好的选择?

[英]Parsing raw HTTP in C# - or some better option?

I have a raw socket I want to make HTTP requests over. 我有一个原始套接字,想通过它发出HTTP请求。 I would like to get back nicely-parsed-for-me http responses. 我想找回我很好的http回复。 Ideally I could feed this raw socket to HttpClient - something in a standard library. 理想情况下,我可以将此原始套接字提供给HttpClient-标准库中的内容。 "TheWrapperClass" around the socket would allow me to use higher level instructions like again - the ones from HttpClient/HttpClientHandler like : clientHandler.ClientCertificates or clientHandler.Credentials etc. 套接字周围的“ TheWrapperClass”将允许我再次使用更高级别的指令-来自HttpClient / HttpClientHandler的指令,例如: clientHandler.ClientCertificatesclientHandler.Credentials等。

Something like this maybe?: 可能是这样的:

HttpClientHandler clientHandler = new HttpClientHandler();
clientHandler.SocketFactory = mySocket/FactoryGoesHere???
HttpClient client = new HttpClient(new CustomMessageHandler());
var resp = await client.GetAsync("http://whatever");

I'm thinking of something like SSLSocketFactory from Java - is there an equivalent of this in .NET that I just haven't found yet? 我在想Java之类的SSLSocketFactory之类的东西-.NET中是否有与我刚发现的等效项?

At the end of the day - I really only want to have a library to invoke that writes HTTP to the wire easily and reads HTTP from the wire easily. 归根结底,我真的只想拥有一个要调用的库,该库可以轻松地将HTTP写入网络,并轻松地从网络中读取HTTP。 If I had that I don't need HttpClient. 如果有的话,我不需要HttpClient。 Alternatively I need a way to use HttpClient to send bytes down the socket I give the class. 另外,我需要一种方法使用HttpClient在我给类的套接字上发送字节。

Edit: I tried using a HttpMessageHandler but the HttpRespons is one that I hand craft. 编辑:我尝试使用HttpMessageHandler,但HttpRespons是我手工制作的。 I need something that reads a stream and parses the http for me. 我需要读取流并为我解析http的内容。

If you don't have a need for executing JavaScript, SimpleBrowser might fit for you: https://github.com/SimpleBrowserDotNet/SimpleBrowser 如果您不需要执行JavaScript,SimpleBrowser可能适合您: https : //github.com/SimpleBrowserDotNet/SimpleBrowser

It will not expose a raw socket for you to use as a bi-directional stream, but it will allow you to navigate via HTTP and receive an HTTP response. 它不会公开原始套接字供您用作双向流,但是它将允许您通过HTTP导航并接收HTTP响应。 The HTTP response can either be the raw text response from the web server, or an parsed XML (XHTML) document. HTTP响应可以是来自Web服务器的原始文本响应,也可以是已解析的XML(XHTML)文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM