I have developed a Web API, I can access my api by using HttpClient in .NET 4 and 4.5 but I want to access this api from an existing .NET 3.5 application. Is it possible? I have learned from internet that HttpClient is not supported in .net 3.5, so how I consume this service in .net 3.5 application?
Checkout this link for .net version 3.5:
OR TRY THIS FOR 3.5
System.Net.WebClient client = new System.Net.WebClient();
client.Headers[HttpRequestHeader.ContentType] = "application/json";
client.BaseAddress = "ENDPOINT URL";
string response = client.DownloadString(string.Format("{0}?{1}", Url, parameters.UrlEncode()));
This is how I am making call in .net 4.5.
var url = "YOUR_URL";
var client = new HttpClient();
var task = client.GetAsync(url);
return task.Result.Content.ReadAsStringAsync().Result;
You could use WebRequest
// Create a request for the URL.
var request = WebRequest.Create ("http://www.contoso.com/default.html");
request.ContentType = contentType; //your contentType, Json, text,etc. -- or comment, for text
request.Method = method; //method, GET, POST, etc -- or comment for GET
using(WebResponse resp = request.GetResponse())
{
if(resp == null)
new Exception("Response is null");
return resp.GetResponseStream();//Get stream
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With