HTTP library that is independent of HttpWebRequest

I need a C # HTTP library that is independent of HttpWebRequest, since I cannot access this from the environment in which I need to run my code (Unity WebPlayer).

Ideally, it will be light weight, but any suggestions are welcome!

I just need to be able to perform simple HTTP GET and POST requests, but it's better to support REST.

Thanks!

Change As people pointed out, HttpWebRequest is not in System.Web, but the fact remains - I can’t use it. I updated my post above.

This post http://forum.unity3d.com/threads/24445-NotSupportedException-System.Net.WebRequest.GetCreator shows the same error I am getting.

+4
source share
3 answers

Implementing your own simple HTTP client using Socket is not that difficult.

Just use TcpClient ().

For the protocol itself, go down to the query connectivity paradigm. A typical GET request would look like this:

GET /url HTTP/1.1 Host: <hostname-of-server> Connection: close 

For the code itself (from memory)

 TcpClient client = new TcpClient(); IPEndPoint target = ... // get an endpoint for the target using DNS class client.Connect(target); using(NetworkStream stream = client.GetStream()) { // send the request. string request = "GET /url HTTP/1.1\r\nConnection: close\r\n\r\n"; stream.Write(Encoding.ASCII.GetBytes(request)); // then drain the stream to get the server response } 

Note that you will need to wrap this code with a simple class that provides HTTPWebRequest, such as semantics.

+2
source

Take a look at System.Net.HttpWebRequest .

It is located in the System.dll .

Documentation: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx

HttpRequest is located in System.Web , which is probably what you were thinking.

+1
source

HttpWebRequest is in the System assembly, not in System.Web (you may be confused with the HttpRequest , which is used in ASP.NET). It is available in all versions of the .NET Framework (including Silverlight, WP7, and Client Profile).

+1
source

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


All Articles