我想从网站下载一些图片,但它必须发送带有“referer”的请求。像这样的代码:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(imgUrl);
CookieContainer cc = new CookieContainer();
request.CookieContainer = cc;
request.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5";
request.Referer = "http://www.xxxxx.com/xxx/xxx/list_78542.html";
request.CookieContainer = cc;
HttpWebResponse myResponse = (HttpWebResponse)request.GetResponse();
using (Stream stream = myResponse.GetResponseStream())
...
但是,当我想在 Windows 商店应用程序中执行此操作时,它在 WebRequest 中没有属性“Referer”,我尝试使用它(如下所示)来设置“UserAgent”和“Referer”
request.Headers["UserAgent"] = UserAgent;
request.Headers["Referer"] = Referer;
但它会引发错误“必须使用适当的属性或方法修改'Referer'标头。”
我该怎么办,请帮帮我?
谢谢。