1
I have a project in . Net Framework 4.6.1, and in my research I concluded that I can use the class Webrequest to request other web services via backend.
- I wish I could make requests using any http verb.
- Also be able to make use of SSL/TLS protocol when necessary.
- The Webrequest class is the only one available for this purpose?
- In addition to the above requirements, considering performance and security, this is the most appropriate way to establish connections through the . net platform?
Editing:
Consider the following code snippets:
Case 1:
public class MyServiceController : ApiController
{
public void Post()
{
// ...
using (var httpClient = new HttpClient())
{
var result = httpClient.GetAsync("https://answall.com");
}
// ...
}
}
Case 2:
public class MyServiceController : ApiController
{
public void Post()
{
// ...
var request = WebRequest.Create("https://answall.com");
request.Method = "GET";
// ...
using (var response = request.GetResponse())
{
// ...
}
}
}
1. If both of you can assist me with a request in C#, what would be the difference between them? What are the most indicated scenarios?
2. Both have support for any HTTP verb?
3. Both have SSL/TLS protocol support?
4. Which is more performative?
5. Some of them are obsolete and can offer me security risks in the requisition?
Take a look at the class
HttpClient
and see if it fits– Kevin Kouketsu
@Kevinkouketsu thank you so much for the comment. If you can post a reply with a brief comparison between Webrequest and Httpclient I believe you can accept it now.
– Jedaias Rodrigues