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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:30:16+00:00 2026-06-02T21:30:16+00:00

As an example I am trying to alter the GetResponse() function of HttpWebRequest class

  • 0

As an example I am trying to alter the GetResponse() function of HttpWebRequest

class HttpWebRequest_Override : HttpWebRequest
{
    public HttpWebRequest_Override(System.Runtime.Serialization.SerializationInfo SerializationInfo, System.Runtime.Serialization.StreamingContext StreamingContext) 
        : base(SerializationInfo, StreamingContext) { }

    public override WebResponse GetResponse()
    {
        //Edit GetResponse() code here.
    }
}

However I can’t find the standard code for GetResponse() anywhere. Am I expected to write one from scratch? I’d like to Copy+Paste the original code in and then alter it. I already tried looking here but that didn’t help much.

To test if I was even on the right track, I commented out GetResponse() and tried to use the HttpWebRequest_Override as-is (with only the constructor in).

And then using it like:

public static string DownloadText(string url)
{
    try
    {
        var request = (HttpWebRequest_Override)WebRequest.Create(url);
        request.Proxy = null;
        var response = (HttpWebResponse)request.GetResponse();

        using (var reader = new StreamReader(response.GetResponseStream()))
        {
            return reader.ReadToEnd();
        }
    }
    catch (Exception ex) { return "error_program : "+ex.Message; }
}

But this throws the error:

Unable to cast object of type 'System.Net.HttpWebRequest' to type 'bulktest.HttpWebRequest_Override'.

So two questions:

Why isn’t the class working, and where can I find the code for .NET classes so I can alter them?

  • 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-02T21:30:18+00:00Added an answer on June 2, 2026 at 9:30 pm

    WebRequest.Create doesn’t create an instance of your class, it creates an instance of HttpWebRequest, which you derive from. While you can cast an instance of a child as it’s parent, you can’t cast an instance of the parent as the child. The parent isn’t guaranteed to have all of the methods of the child, whereas the child is guaranteed to have to the methods of the parent.

    You can register custom protocols that are handled by your own, derived class or, via configuration, register your class to handle the default protocols. Whether you need to do this is an open question. From your example, a simple wrapper might be sufficient. The wrapper would take a HttpWebRequest instance in the constructor and delegate the standard WebRequest methods to that instance. Any new methods would use the underlying instance’s methods for their work and layer your additional functionality on top of it.

    EX:

     var request = new WebRequestWrapper((HttpWebRequest)WebRequest.Create(url));
     var html = request.DownloadText();
    

    Where your class might look like:

     public class WebRequestWrapper
     {
          private HttpWebRequest _request;
    
          public WebRequestWrapper(HttpWebRequest request)
          {
              this._request = request;
          }
    
          public string DownloadText()
          {
              using (var response = (HttpWebResponse)this._request.GetResponse())
              using (var reader = new StreamReader(response.GetResponseStream()))
              {
                  return reader.ReadToEnd();
              }
          }
     }
    

    FWIW, I don’t like catching the exception and returning a string. I’d rather let the exception bubble up since the method returns a string.

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

Sidebar

Related Questions

Am trying to run pdf.js example on localhost and after downloading i did make
iam trying play animation with xcode,in specefic Time for example after 3 minutes play
Here's what I'm trying to achieve: Before: www.example.com/index.php?page=about&pg=5 After: www.example.com/about.html?pg=5 The URL must specifically
is it possible elasticsearch to handle queries containing typos . Example trying to query
I am using UICatalog example and trying to find whether it is possible to
I'm using Mirven's Twitter OAuth Sinatra example and trying to figure out how I
I am trying an example: String hashAlgorithm =sha-256 ... md=MessageDigest.getInstance(hashAlgorithm); byte[] enteredPasswordDigest = md.digest(policy.getPassword().getBytes());
for example I'm trying to get the data from database like: using (ExplorerDataContext context
i am trying one example from Here for ontouch image zoom and touch on
I am learning and trying simple example using node.js and mongoskin. here is my

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.