Sending / receiving data to a server in C #

In my program, I need to request data from the server and, after collecting the response, use the returned data for further processing.

I use the class "system.net.webrequest" for this. I have few questions about this:

  • after I receive the data (data have a minimum size of 0.5 MB). I need to process all the data in order to get some kind of result. I was thinking of storing the returned data in a txt file, and then reading the data from this file and processing it.

Is this a better idea? If not, can you suggest.

  • I send a request to several servers (> 10 servers) and using the data from them. I noticed that for some reason, if the server is unavailable, my program stops throwing an exception

    Server is not available. The first case of an exception of type "System.Net.WebException" occurred in System.dll.

How can I solve this problem? Any idea?

Eliminate your help.

Thanks Rahul

+3
source share
2 answers

Regarding the exception; implement the area try/ catchand perform the appropriate actions (perhaps by launching the error and programming it for several minutes).

I'm not quite sure what the first question is, since we do not know what data / system is, but some thoughts:

  • , , , - (request.Accept = "gzip,deflate"; , HttpWebRequest); , , ,
  • , , Dictionary<,>, ; , "", , "" "" ; p
+3

, . , , .

, Try/Catch ():

foreach (var server in serverList)
{
    try
    {
        ... fetch data and process ...
    }
    catch (Exception ex)
    {
        // handle exception (log, requeue, etc)
    }
}
+1

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


All Articles