Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9046165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:35:13+00:00 2026-06-16T11:35:13+00:00

I successfully did that before in the past 4-5 maybe 6 months back, but

  • 0

I successfully did that before in the past 4-5 maybe 6 months back, but now i see the site has changed .I am able to get the desired search result using HttpWebRequest the issue is with downloading the CSV file.

The download won’t work. I reproduced this with WebClient, get all the cookies but still it won’t work.

When I do so, I get this in the file

…..meta http-equiv="refresh" content="0; url=’http://www.google.com/trends#content=1&geo=US-AL&q=snooker&cmpt=q&hl=en-AU’">

location.replace(“http://www.google.com/trends#content\x3d1\x26geo\x3dUS-AL\x26q\x3dsnooker\x26cmpt\x3dq\x26hl\x3den-AU”)

The code to download file is as follows:

public void downloadsheet(string url, string path)
    {
        try
        {
            using (WebClient client = new WebClient())
            {



                string tmpCookieString = string.Empty;

                string[] array = webBrowser1.Document.Cookie.Split(new char[]
                        {
                            ';'
                        });
                for (int i = 0; i < array.Length; i++)
                {
                    string cookie = array[i];
                    string name = cookie.Split(new char[]
                            {
                                '='
                            })[0];
                    string value = cookie.Substring(name.Length + 1);

                    //client.Headers.Add(name, value);
                    if (i < array.Length - 1)
                    {
                        tmpCookieString = tmpCookieString + name + "=" + value + ";";
                    }
                    else
                    {
                        tmpCookieString = tmpCookieString + name + "=" + value;
                    }
                }

                client.Headers.Add(HttpRequestHeader.Cookie, tmpCookieString);
                client.Headers.Add("Accept", "text/html, application/xhtml+xml, */*");
                client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)");
                client.Headers.Add("Accept-Language", "en-US");
                using (FileStream file = File.Create(path))
                {
                    byte[] bytes = client.DownloadData(url);
                    file.Write(bytes, 0, bytes.Length);
                }
            }
        }
        catch (Exception exp_DE)
        {
        }
    }

The url is use is:

http://www.google.com/trends/trendsReport?hl=en-AU&q=snooker&geo=US-AL&cmpt=q&content=1&export=2

If I use WebBrowser control to navigate to the respective link above it does open up a dialogue box..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T11:35:17+00:00Added an answer on June 16, 2026 at 11:35 am

    The problem is the HttpOnly cookies (i.e. SID and HSID) are missing from WebBrowser.Document.Cookie for security purpose.

    Here is the solution:

    [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
    static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData, ref uint pcchCookieData, int dwFlags, IntPtr lpReserved);
    const int INTERNET_COOKIE_HTTPONLY = 0x00002000;
    
    private static string GetGlobalCookies(string uri)
    {
        uint datasize = 2048;
        StringBuilder cookieData = new StringBuilder((int)datasize);
        if (InternetGetCookieEx(uri, null, cookieData, ref datasize, INTERNET_COOKIE_HTTPONLY, IntPtr.Zero)
            && cookieData.Length > 0)
        {
            return cookieData.ToString();
        }
        else
        {
            return null;
        }
    }
    
    public void downloadsheet(string url, string path)
    {
        try
        {
            using (WebClient client = new WebClient())
            {
                string tmpCookieString = GetGlobalCookies(webBrowser1.Url.AbsoluteUri);
    
                client.Headers.Add(HttpRequestHeader.Cookie, tmpCookieString);
    
                client.Headers.Add("Accept", "text/html, application/xhtml+xml, */*");
                client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)");
                client.Headers.Add("Accept-Language", "en-US");
                using (FileStream file = File.Create(path))
                {
                    byte[] bytes = client.DownloadData(url);
                    file.Write(bytes, 0, bytes.Length);
                }
            }
        }
        catch (Exception exp_DE)
        {
        }
    }
    

    Of course, you should sign in your account before calling InternetGetCookieEx.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Although I think that I did it before successfully, but this code does not
Successfully used jquery-infinite-carousel in the past but for my current project I need it
I have successfully added information to shapefiles before (see my post on http://rusergroup.swansea.ac.uk/Healthmap.ashx?HL=map ).
Disclaimer: I did check other questions that seemed related, but this one is much
I know this Question has been asked many times before, but none has solved
I'm pretty sure it has been asked before, but I could not find anything
I was successful in writing the query that lists salesmen that did sell to
I did an Android project and run it. It ran successfully. I developed a
After successfully acquiring an oauth_token for a user, I am able to get successful
I successfully compiled ActionBarSherlock in Eclipse. But I get 75 errors when I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.