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

  • Home
  • SEARCH
  • 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 7755675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:37:26+00:00 2026-06-01T12:37:26+00:00

I am using the WebClient.DownloadString() method to download some data. I am using the

  • 0

I am using the WebClient.DownloadString() method to download some data. I am using the following code:

static void Main(string[] args)
    {
        string query = "select+%3farticle+%3fmesh+where+{+%3farticle+a+npg%3aArticle+.+%3farticle+npg%3ahasRecord+[+dc%3asubject+%3fmesh+]+.+filter+regex%28%3fmesh%2c+\"blood\"%2c+\"i\"%29+}";
        NameValueCollection queries = new NameValueCollection();
        queries.Add("query", query);
        //queries.Add("output", "sparql_json");
        using (WebClient wc = new WebClient())
        {
            wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            wc.QueryString = queries;
            string result = wc.DownloadString("http://data.nature.com/sparql");
            Console.WriteLine(result);
        }
        Console.ReadLine();
    }

With this code, tt works fine and gives me an xml string as the output. But I would like to get a JSON output and hence I un-commented the line

queries.Add("output", "sparql_json");

and executed the same program and it seems to be fetching an error message from the server.

However, if I try to use a web browser and use the same url (as given below), it gives me a JSON as expected:
URL that works in browsers

I am wondering what the problem could be. Especially when it works in a browser and not using a webclient. Is the webclient doing something different here?

Please note that I also tried to specify the query as

query + "&output=sparql_json"

But that does not work either.

Could someone please tell me what the problem might be?

Thanks

  • 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-01T12:37:27+00:00Added an answer on June 1, 2026 at 12:37 pm

    Add wc.Headers.Add("Accept","application/json");. Here is the full source I tested

    string query = "select ?article ?mesh where { ?article a npg:Article . ?article npg:hasRecord [ dc:subject ?mesh ] . filter regex(?mesh, \"blood\", \"i\") }";
    NameValueCollection queries = new NameValueCollection();
    queries.Add("query", query);
    queries.Add("output", "sparql_json");
    using (WebClient wc = new WebClient())
    {
        wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
        wc.Headers.Add("Accept","application/json");
        wc.QueryString = queries;
        string result = wc.DownloadString("http://data.nature.com/sparql");
        Console.WriteLine(result);
    }
    Console.ReadLine();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was using a BackgroundWorker to download some web sites by calling WebClient.DownloadString inside
I'm running the following code; using (WebClient wc = new WebClient()) { string page
I'm using the following code: if (e.Data.MessageArray[0] == !streams) { try { WebClient webclient
I am using the WebClient class to post some data to a web form.
I'm using the following code to simulate a page post. (I'm subclassing WebClient so
I'm using WebClient.DownloadString(url) to download a web page, when a url a 404 web
using WebClient client = new WebClient(); var data = client.DownloadString(url); then using Regex to
I am using a WebClient to download a string from a website (which just
I'm using WebClient to download some text from a web-page, like this: WebClient wc
I'm using the WebClient.DownloadString method to GET a response from a website. Sometimes, the

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.