Call web APIs in C# using .NET framework 3.5
Asked Answered
S

1

28

I am trying to find the nearest store given a zip code. I came to know that yelp and foursquare provides the required APIs to do this. I am using .NET 3.5 framework. How do you make the http requests and handle the responses.Most of the solns on the web give it for .NET 4.5 onwards which includes the usage of HTTPClient class.

Sow answered 14/3, 2014 at 6:38 Comment(0)
L
44

You can use System.Net.WebClient class to make an http request.

 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\": \"[email protected]\",\"Password\": \"pass#123\"}")));

There are also other methods which can be used, but that depends on your requirements. You can find more details here from MSDN.

Lovell answered 14/3, 2014 at 8:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.