Web client class inheritance

C # 2008

I'm not sure how much work is inherited from the web client class.

I am currently using it in my project. And I can’t change anything. The client would like to have a timeout after a certain period of time. The web client does not have this.

In order not to reinvent the wheel, I am thinking of inheriting from the web client and adding this property.

Do you think this is the right solution? Could this mean more work, just to add it. What is the easiest way to do this?

Many thanks,

+3
source share
1 answer

-, -, ( 0 ). GetWebRequest:

protected override WebRequest GetWebRequest(Uri address) 
{ 
    var req = base.GetWebRequest(address); 
    var httpReq = req as HttpWebRequest;
    if (httpReq != null && Timeout > 0) 
    {
        httpReq.Timeout = Timeout; 
    } 

    return req; 
} 
+2

Source: https://habr.com/ru/post/1708539/


All Articles