C# - How to make a HTTP call

前端 未结 3 826
花落未央
花落未央 2020-11-29 08:28

I wanted to make an HTTP call to a website. I just need to hit the URL and dont want to upload or download any data. What is the easiest and fastest way to do it.

I

3条回答
  •  天命终不由人
    2020-11-29 08:53

    If you don't want to upload any data you should use:

    webRequest.Method = "GET";
    

    If you really don't care about getting any data back (for instance if you just want to check to see if the page is available) use:

    webRequest.Method = "HEAD";
    

    In either case, instead of webRequest.GetRequestStream() use:

    WebResponse myWebResponse = webRequest.GetResponse();
    

提交回复
热议问题