使用.NET framework 3.5在C#中调用Web API

我试图找到最近的商店给出一个邮政编码。 我开始知道yelp和foursquare提供了执行此操作所需的API。 我使用的是.NET 3.5框架。 你如何制作http请求并处理响应。网上的大部分解决方案都为.NET 4.5以上提供了包括HTTPClient类的使用。

您可以使用System.Net.WebClient类来发出http请求。

System.Net.WebClient client = new System.Net.WebClient(); client.Headers.Add("content-type", "application/json");//set your header here, you can add multiple headers string s = Encoding.ASCII.GetString(client.UploadData("http://localhost:1111/Service.svc/SignIn", "POST", Encoding.Default.GetBytes("{\"EmailId\": \"admin@admin.com\",\"Password\": \"pass#123\"}"))); 

还有其他方法可以使用,但这取决于您的要求。 您可以在 MSDN中找到更多详细信息。