1

I have a google docs spreadsheet set to publish as RSS -> json, and I'm using the code below to retrieve it:

public void getDocData()
{
    String url = "https://spreadsheets.google.com/blah blah blah/basic?alt=json";
    using (var w = new WebClient())
    {
        //here's where the problem is
        String json_data = w.DownloadString(url);

        //blah blah parse json_data;
     }
 }

My problem is that the DownloadString is taking an inordinately long amount of time (10-15 seconds), and I have absolutely no idea why. The weird thing is I have a node/javascript app that uses the exact same link and an http.get request and doesn't have the same problem.

Anyone have any ideas?

Brad M
  • 7,857
  • 1
  • 23
  • 40
Keirathi
  • 397
  • 1
  • 5
  • 18

2 Answers2

1

Try to use acync msdn

public void getDocData()
{
  String url = "https://spreadsheets.google.com/blah blah blah/basic?alt=json";
  using (var w = new WebClient())
  {
    //here's where the problem is
    String json_data = w.DownloadStringAsync(url);

    //blah blah parse json_data;
  }
}

more details

AndreyMaybe
  • 309
  • 1
  • 2
  • 8
1

Based on your symptoms, I'm inclined to think that Google Docs has nothing to do with this. Have you tried investigating similar issues related directly to WebClient? For example, make sure it's not having proxy resolution issues:

using (var w = new WebClient())
{
    w.Proxy = null;
    ...
Community
  • 1
  • 1
StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315
  • I actually use the exact same code to get a json response from the Twitch.tv API and it doesn't have the same issues at all. – Keirathi Jun 13 '13 at 18:43
  • @Keirathi: You also have a node app that accesses the same Google API, and it returns quickly. Obviously the issue is related in some way to WebClient. Maybe it's not an issue because of protocol (http/https) or DNS lookup (maybe something in your hosts file?). I'd still suggest looking for similar issues with WebClient itself first. – StriplingWarrior Jun 13 '13 at 18:50
  • 1
    Doh, you were right. Setting the Proxy to null completely fixed it. Guess I should have tried your method first :P Thanks! – Keirathi Jun 13 '13 at 19:02