C#调用Get请求

    xiaoxiao2022-07-04  125

    /// <summary> /// 发起一个HTTP请求(以GET方式) /// </summary> /// <param name="url"></param> /// <returns></returns> public string HttpGet(string url) { WebRequest myWebRequest = WebRequest.Create(url); WebResponse myWebResponse = myWebRequest.GetResponse(); Stream ReceiveStream = myWebResponse.GetResponseStream(); string responseStr = ""; if (ReceiveStream != null) { StreamReader reader = new StreamReader(ReceiveStream, Encoding.UTF8); responseStr = reader.ReadToEnd(); reader.Close(); } myWebResponse.Close(); return responseStr; }

     

    最新回复(0)