WebClient w = new WebClient(); w.Headers.Add(HttpRequestHeader.Accept, "application/json");
HttpWebRequest与WebRequest不能添加Header,WebClient可以。
WebClient w = new WebClient(); w.Headers.Add(HttpRequestHeader.Accept, "application/json"); using (StreamReader sr = new StreamReader(w.OpenRead("http://192.168.1.123:9763/services/ccjy.HTTPEndpoint/getrestnews?num=4"))) { string a =sr.ReadToEnd(); }