故事语录 发表于 2018-10-22 09:40:26

通过http地址请求获取Json数据的几种写法

本帖最后由 故事语录 于 2018-10-30 10:59 编辑

注:需引用Newtonsoft.Json.dll、system.io、System.Web.Extensions.dll、 System.Web.Script.Serialization、 System.Collections.Generic、 System.Collections.Specialized、 System.Net、 System.Net.Security、 System.Security.Cryptography.X509Certificates。里面包含了json转任意实体对象集合的方法。需要用到cookie信息的地址需设置cookie信息。如例子:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "GET";
            // request.ContentType = "application/json";
            CookieContainer cookies = new CookieContainer();
            cookies.SetCookies(new Uri(url), "_ga=GA1.2.891077184.1538966911, __nks=1540274524282-n9mfdDbSaLR0sfj07CJyVkvOHKqEjWNY,__nks.sig=pM7hbgJLfVN6ypGNc2rqz8IsuPo,__csaks=1540274524361-K1XVtq_uKXqIVkfrAZJcRG6zMwajENC8,__csaks.sig=t-MRDBjcr9KMZ-uUOMyPKPhRbrg,__tgc=15c6dfdd-2e73-4b15-bab7-57b6cbd6531d,__tgc.sig=KIE937Db3F188G1kpa_-cxkecps,_gid=GA1.2.944360251.1540274528,_gat_gtag_UA_92889437_5=1");
            request.CookieContainer = cookies;
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            StreamReader stream = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string jsonstr = stream.ReadLine();

页: [1]
查看完整版本: 通过http地址请求获取Json数据的几种写法