关于请求添加HttpRequestHeader

            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();                
            }

转载于:https://www.cnblogs.com/denglinhai/p/3378430.html

你可能感兴趣的:(json)