Maybe I can’t find the WebClient
but seems to find WebRequest
, just ask for the HEAD
not the data. You cannot use the GET
, this returns all content. I believe it is the best that can be done. For this you need set the requisition method class WebRequest
. Have examples in the documentation without using the HEAD
but just do this:
webRequest.Method = "HEAD";
I found a question in the OS who did this:
class Program {
static void Main(string[] args) {
try {
System.Net.WebRequest wc = System.Net.WebRequest.Create("http://www.imdb.com"); //args[0]);
((HttpWebRequest)wc).UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.2.153.1 Safari/525.19";
wc.Timeout = 1000;
wc.Method = "HEAD";
WebResponse res = wc.GetResponse();
var streamReader = new System.IO.StreamReader(res.GetResponseStream());
Console.WriteLine(streamReader.ReadToEnd());
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}
}
}
I was responding when the AP showed that I was on the wrong track. I’ll leave it here so I can help someone. But this part does not answer what was asked.
Essentially it’s catch up with the asynchronous version of the method used, so the application "stuck" is not waiting for the answer (one of the ways with Webrequest
). You will still receive it, you may or may not discard it, but you need to receive it somehow.
using System.Net;
/* .. SNIP .. */
WebClient foo = new WebClient();
foo.DownloadStringAsync("http://siteDaAplicacao.com.br/Pagina.aspx");
I put in the Github for future reference.
I liked the question because I ended up learning some things I didn’t know, although I knew the essence. I discovered that the term used for this is fire and Forget. I found some examples as this that work differently (basically came out of this response in the OS).
I don’t know if I understand what you want. Do you want to make the request but don’t want any response? Is that right? What’s the point? Know if the server is alive? You just don’t want to waste time on getting the answer?
– Maniero
@Mustache I just want to fire the process, and the answer can be very big. I’ll make the same request at once for several pages and their combined response can be several megas. Since the answer is irrelevant to the console application, I would like to not have to receive all this information.
– Oralista de Sistemas
Can it be with
async
? You already know the solution, right? :)– Maniero
@bigown even though I use asynchronous methods the server response is still sent to my machine. That’s what I want to avoid.
– Oralista de Sistemas
As far as I know, there is no way to avoid any response, perhaps I can avoid the content coming. And I still can’t imagine why I need this.
– Maniero
I even know a way to avoid the answer to my application - manipulate the headers of TCP packets to let them know that the response address is different. But I can’t do that. And it wouldn’t be very nice if the address I put in existed, the recipient could look at it as a Ddos...
– Oralista de Sistemas