C#请求url,获取响应的脚本
public string ResultOfApi(string url) { //发送请求 HttpWebRequest request = null; HttpWebResponse response = null; request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "Get"; request.ContentType = "application / x - www - form - urlencoded"; request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"; request.Accept = "text / html,application / xhtml + xml,application / xml; q = 0.9,image / webp,image / apng,*/*;q=0.8"; request.KeepAlive = true; //获取响应 response = (HttpWebResponse)request.GetResponse(); Stream S = response.GetResponseStream(); StreamReader streamreader = new StreamReader(S); string result = streamreader.ReadToEnd(); return result }
原文地址:https://www.cnblogs.com/dinghanhua/p/10015201.html
时间: 2024-10-03 23:54:40