Reputation: 61
just starting to create an API to my a web application using the ASP.NET MVC4 Web API project template. http://www.asp.net/mvc/mvc4
No problems with the API so far, but I was about to write a small C# app to test the API.
Almost all the sample I can find is using the a class called HttpClient.
Where can I find the HttpClient and how do I install it?
Upvotes: 4
Views: 13775
Reputation: 21998
It's on nuget, search for HttpClient
http://nuget.org/packages/System.Net.Http
Upvotes: 8
Reputation: 6888
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 a REST interface use RestSharp but you would need XSD first.
Upvotes: 3
Reputation: 10221
Rather than using the build in HttpClient class of the .NET framework which has a lot of issues when dealing with StatusCodes that are different than the expected ones. I recommend using a library called RestSharp.
It has become .NET Http/Rest client of choice, you can get it here: http://restsharp.org/
It is a very powerful library that is perfectly suited to do what you want.
Upvotes: 9
Reputation: 2333
If the class is not available from your code, then you could download it from a NuGet package, like described in the article:
http://code.msdn.microsoft.com/Introduction-to-HttpClient-4a2d9cee
or you can try to locate it inside the namespace: System.Net.Http
There is also an example for you wich should get you started!
Upvotes: 1