Invoking a URL - c#

后端 未结 5 2062
渐次进展
渐次进展 2021-01-11 21:27

I m trying to invoke a URL in C#, I am just interested in invoking, and dont care about response. When i have the following, does it mean that I m invoking the URL?

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-11 21:39

    First) Create WebRequest to execute URL.
    Second) Use WebResponse to get response.
    Finally) Use StreamReader to decode response and convert it to normal string.

    string url = "Your request url";
    WebRequest request = HttpWebRequest.Create(url);
    WebResponse response = request.GetResponse();
    StreamReader reader = new StreamReader(response.GetResponseStream());
    string responseText = reader.ReadToEnd();
    

提交回复
热议问题