我正在尝试根据邮政编码查找最近的商店。我开始知道 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\"}")));
还有其他方法可以使用,但这取决于您的要求。您可以找到更多详细信息 here 来自 MSDN。
关于c# - 使用 .NET Framework 3.5 在 C# 中调用 Web API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22397865/