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 6368911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:44:07+00:00 2026-05-25T00:44:07+00:00

I have a WebClient and I’m subscribing to the OnDownloadStringCompleted event handler. When the

  • 0

I have a WebClient and I’m subscribing to the OnDownloadStringCompleted event handler. When the server responds with a header of 400 Bad Request, the OnDownloadStringCompleted Never gets triggered. I still need what the response is even though the header says 400. Is there a way to bypass this?

Heres the URL I’m attempting to fetch:
https://graph.facebook.com/me?access_token=your_token

  • 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-05-25T00:44:08+00:00Added an answer on May 25, 2026 at 12:44 am

    First off all in my testing I find that the DownloadStringCompleted does fire.

    However an attempt to read the event args Result property will throw an error. You need to test the event args Error property to determine if an error occured. If it has this property will hold a reference to a WebException.

    Fortunately the WebException has a Response object which is of type WebResponse. You can get the response string from this using a little function:-

        string StringFromWebResponse(WebResponse response)
        {
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                return reader.ReadToEnd();
            }
        }
    

    But there is a problem. This is only available when using the ClientHTTP stack not the BrowserHTTP stack. So you need something like this line of code in your app:-

        WebRequest.RegisterPrefix("https://graph.facebook.com", System.Net.Browser.WebRequestCreator.ClientHttp);
    

    So then code like this will work:-

            WebClient client = new WebClient();
            client.DownloadStringCompleted += (s, args) =>
            {
                string result;
    
                if (args.Error == null)
                {
                    result = args.Result;
                    //Do something with the expected result
                }
                else
                {
                    WebException err = args.Error as WebException;
    
                    result = StringFromWebResponse(err.Response);
                    // Do something with the error result
                }
            };
    
            client.DownloadStringAsync(new Uri("https://graph.facebook.com/me?access_token=your_token", UriKind.Absolute));
    

    Oh but there is possibly another problem. I don’t know anything about the facebook API but if there is a dependency on cookies then by default the ClientHTTP stack doesn’t manage cookies itself. To handle cookies properly you need to assign a common CookieContainer to each HttpWebRequest used. WebClient doesn’t allow you access to the WebRequest object used so you’ll need to drop to using WebRequest/WebResponse directly.

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

Sidebar

Related Questions

I have a client application (windows service) which sends a request (WebClient.UploadString()) to a
I have object of type WebClient which successfully connects to web server. But when
I have created an Asynchronous WebClient request inside a class as follows: public class
In it's very basic form I have a WebClient request for some xml in
I have an app that uploads files to server using the webclient. I'd like
I have to create mutiple web request to same URL using webclient. I spawn
I have a download manager of sorts that uses WebClient.DownloadFileAsync. Webclient doesn't seem to
I have a problem downloading particular file types by WebClient. So there are no
I have this class called SiteAsyncDownload.cs Here's the code: public class SiteAsyncDownloader { WebClient
I have in my Form constructor, after the InitializeComponent the following code: using (WebClient

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.