We can Get and Post data from a Web API using Web client. Web client provides common methods for sending and receiving data from Server. Here, I have not used any authentication and authorization mechanism. This is simple - it's just for sending and receiving data from API.
First, you have to assign the API Endpoint on a variable. Here, I have created one static class to assign the API Endpoint.
- public static class StaticItems
- {
- public static string EndPoint = "http://localhost:8088/api/";
- }
Here, I have also created a class of name City.
- public class CityInfo
- {
- public int CityID { get; set; }
- public int CountryID { get; set; }
- public int StateID { get; set; }
- public string Name { get; set; }
- public decimal Latitude { get; set; }
- public decimal Longitude { get; set; }
- }
Receiving Data from API
This function retrieves data from API. Here, this function returns the list of cities. The data received from the API is in JSON format so I have deserialized that JSON data to an Object List. The Keyword DownloadString is used for retrieving data from Server.

Abanoub haliemPosted Jan 21, 2021, 1:32 PM
I have an exception " The underlying connection was closed: An unexpected error occurred on a send ."
Michael BrownPosted Dec 7, 2020, 12:50 PM
Every time I send to the server, the data is null????
amitPosted Jul 2, 2020, 8:30 AM
When i m trying to access web api with the help of httpclient, i m getting following error... The type or namespace name 'HttpClient' could not be found (are you missing a using directive or an assembly reference?)
Pankajkumar PatelPosted Aug 12, 2019, 11:24 PM
Good article