HttpClient app for C #

just started creating an API for my web application using the ASP.NET MVC4 Web API project template. http://www.asp.net/mvc/mvc4

No problem with the API so far, but I was going to write a small C # application to test the API.

Almost all the samples I can find are using the HttpClient class.

Where can I find HttpClient and how to install it?

+4
source share
4 answers

Instead of using the assembly in the HttpClient class of the .NET platform, which has a lot of problems when working with StatusCodes that are different than expected. I recommend using a library called RestSharp .

He became the selected .NET Http / Rest client, you can get it here: http://restsharp.org/

This is a very powerful library that is ideal for doing what you want.

+9
source

This is on nuget, an HttpClient search

http://nuget.org/packages/System.Net.Http

+8
source

Use WebRequest as described here

  // Create a new 'Uri' object with the specified string. Uri myUri =new Uri("http://www.contoso.com"); // Create a new request to the above mentioned URL. WebRequest myWebRequest= WebRequest.Create(myUri); // Assign the response object of 'WebRequest' to a 'WebResponse' variable. WebResponse myWebResponse= myWebRequest.GetResponse(); 

If its REST interface uses RestSharp, but first you need XSD.

+3
source

If the class is not accessible from your code, you can download it from the NuGet package, as described in the article:

http://code.msdn.microsoft.com/Introduction-to-HttpClient-4a2d9cee

or you can try to find it in the namespace: System.Net.Http

There is also an example for you to start with!

+1
source

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


All Articles