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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:14:23+00:00 2026-05-25T14:14:23+00:00

I am working on a client for a REST API. The server returns 4xx

  • 0

I am working on a client for a REST API. The server returns 4xx responses as a matter of course. At the moment, I am using HttpWebRequest/HttpWebResponse to make the calls. The problem is that HttpWebRequest throws an exception on 4xx (and 5xx) codes. I am catching the exception, and then (usually) sending another request based on the data in the 4xx message (e.g., try POST, then MERGE in a failure).

This works, but having to recreate the TCP/HTTP connection every time is expensive. What I want to be able to do is a get a response stream or object that has the response data, but does not throw an exception, allowing me to make another request on the connection (via keep-alive). This should reduce the connection overhead, and boost performance.

One way I have looked at is using the TcpClient directly, but that is a headache, as I then have to write code to support chunked data, encodings, proxies, etc. I am hoping to avoid this.

Is there a way to prevent WebExceptions using the System.Net HTTP client? If not, are there any other options (hopefully open source)? Any suggestions are very welcome.

  • 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-25T14:14:23+00:00Added an answer on May 25, 2026 at 2:14 pm

    Not sure why your HTTP connection would be getting closed due to an exception, however, if you use the HttpClient from here http://nuget.org/List/Packages/HttpClient it does not throw an exception on a 400.

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

Sidebar

Related Questions

I'm working with Redmine's xml rest api. The service returns xml like in the
I'm using .NET 3.5 and WCF for developing a server-client application. Binding=BasicHttp. I'm working
i am using this tutorial to make android as a Rest client . The
I am working on a client-server application that uses boost::serialization library for it's serialization
I'm working on a client-server Android application and trying to figure out how to
I'm working on a client/server library for a legacy RPC implementation and was running
I am working on a client server system, and am running into issues where
I've got a working SOAP::Lite client. It works against an established server, but so
I'm working with a persistent client/server protocol and I need to design a RESTful
I'm working on a new REST-ful API who's primary/only consumer will be a smart/non-web-browser

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.