冰雹!我想从 NOT PUBLIC Google Site 的页面获取图像。我为此目的使用 WebClient。
var uri =
new Uri("http://sites.google.com/a/MYDOMAIN.COM/SITENAME/" +
"_/rsrc/1234567890/MYIMAGE.jpg");
string fileName = "d:\\!temp\\MYIMAGE.jpg";
if (File.Exists(fileName))
File.Delete(fileName);
using (var webClient = new WebClient())
{
var networkCredential = new NetworkCredential("USERNAME", "PASSWORD");
var credentialCache = new CredentialCache
{
{new Uri("sites.google.com"), "Basic", networkCredential},
{new Uri("www.google.com"), "Basic", networkCredential}
};
webClient.Credentials = credentialCache;
webClient.DownloadFile(uri, fileName);
}
它不下载图像,而是下载带有登录表单的 html 文件。如果我在浏览器中打开此链接,它会显示登录表单,然后我输入用户名和密码,然后我可以看到图像。
我必须如何使用我的凭据通过 WebClient 或 HttpWebRequest 下载文件?