Google Site Data fetching

Posted by inTagger on Stack Overflow See other posts from Stack Overflow or by inTagger
Published on 2009-12-30T15:22:12Z Indexed on 2010/03/23 10:03 UTC
Read the original article Hit count: 333

Hail! I want to fetch image from NOT PUBLIC Google Site's page. I'm using WebClient for this purposes.

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

It doesn't download image, but html file with login form is downloaded. If i open this link in browser it shows me login form then i enter username and password and then i can see the image.

How i must use my credentials to download file with WebClient or HttpWebRequest?

© Stack Overflow or respective owner

Related posts about google

Related posts about google-sites