I have a project in .Net Framework 4.6.1, and in my research I concluded that I can use the WebRequest to make requests to other web services via the backend.
Issue:
Consider the following code snippets:
Case 1:
public class MyServiceController : ApiController
{
public void Post()
{
// ...
using (var httpClient = new HttpClient())
{
var result = httpClient.GetAsync("https://pt.stackoverflow.com");
}
// ...
}
}
Case 2:
public class MyServiceController : ApiController
{
public void Post()
{
// ...
var request = WebRequest.Create("https://pt.stackoverflow.com");
request.Method = "GET";
// ...
using (var response = request.GetResponse())
{
// ...
}
}
}
1. If both can help me make a request in C #, what would be the difference between them? What are the best scenarios?
2. Both have support for any HTTP verb?
3. Both have support for using the SSL / TLS protocol?
4. Which is more performative?
5.
Some of them are obsolete and can give me security risks in the request?