GET不支持GetRequestStream(),所以不能写进去:
string baseUrl = "http://"; string token = ""; try { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(baseUrl); //设置 GET 请求方式 request.Method = "GET"; request.ContentType = "application/x-www-form-urlencoded"; //设置请求头部信息 request.Headers.Add("token", token); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { string result = sr.ReadToEnd(); Console.WriteLine(result); } } catch (Exception ex) { Console.WriteLine(ex.Message); }
标签:请求,GET,Get,request,token,HttpWebRequest,string From: https://www.cnblogs.com/shiningleo007/p/17448544.html