C#用HttpClient抓取jd.com搜索框下拉数据

添加System.Web.dll引用
添加System.Net.Http引用

using System.Net.Http;
using System.Web;

string key = "电脑"; //拼音diannao也可
string url = string.Format("http://dd.search.jd.com/?ver=2&zip=1&key={0}&t={1}", HttpUtility.UrlPathEncode(key), DateTime.Now.Millisecond);
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Referrer = new Uri("http://www.jd.com/"); //这个比较重要
string result = httpClient.GetStringAsync(url).Result;
Console.WriteLine(result);
原文地址:https://www.cnblogs.com/liqipeng/p/4690515.html