I have a Webcrawler application that uses HttpClient in order to do some requests.
When i start the application, a new HttpClient is initialized similar to this:
public static void ResetHttpClient()
{
Client = new HttpClient();
}
After an application restart, the application has to log in freshly which causes trouble due to Limitations to n logins per hour.
Because of that I copied a function from another part of my Apllication that Serializes a List> and saves this list to a file.
I adapted the function in order to test it with HttpClient. My intention was to save the HttpClient and later, when the Program starts/restarts, to load the HttpClient and continue the "Session". Code for the Save function (i know its very ugly with the List just for one entry):
// SAVE
(HttpClient client, DateTime clientCreationDate) httpClientSaveData =
new ValueTuple<HttpClient, DateTime>(Client, ClientCreatedDate);
FileStream stream = new FileStream(@"HttpClient.dat", FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, httpClientSaveData);
stream.Close();
With this code above I am receiving the following errormessage:
System.Runtime.Serialization.SerializationException: 'Type 'System.Net.Http.HttpClient' in Assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.'
Now my question is: Is it even possible to save/load a "Session", eg by saving the cookies? What could be a viable approach to this?