C#: Writing a CookieContainer to Disk and Loading Back In For Use

This problem was bugging me for ages, nothing I could find worked. I worked it out, so putting that information out into the world. Answer using BinaryFormatter: public static void WriteCookiesToDisk(string file, CookieContainer cookieJar) { using(Stream stream = File.Create(file)) { try { Console.Out.Write(“Writing cookies to disk… “); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, cookieJar); Console.Out.WriteLine(“Done.”); … Read more

json call with C# [duplicate]

In your code you don’t get the HttpResponse, so you won’t see what the server side sends you back. you need to get the Response similar to the way you get (make) the Request. So public static bool SendAnSMSMessage(string message) { var httpWebRequest = (HttpWebRequest)WebRequest.Create(“http://api.pennysms.com/jsonrpc”); httpWebRequest.ContentType = “text/json”; httpWebRequest.Method = “POST”; using (var streamWriter = … Read more

Advantages of using application/json over text/plain? [closed]

Let’s assume that you are talking about using JSON versus a custom format (using MIME type text/plain) for passing structured data. Performance may be broken down into different components; e.g. relative time taken to encode the content into the format, relative time taken to decode the format to give you the original content, and relative … Read more

Set the SecurityProtocol (Ssl3 or TLS) on the .net HttpWebRequest per request

Unfortunately, it doesnt look like you can customize this per service point. I would suggest that you file a feature request at the MS Connect website for this area. As a dirty workaround, you could try executing the sites that require a different security protocol in a new appdomain. Static instances are per appdomain, so … Read more

.NET: Is it possible to get HttpWebRequest to automatically decompress gzip’d responses?

Use the HttpWebRequest.AutomaticDecompression property as follows: HttpWebRequest hwr = (HttpWebRequest) WebRequest.Create(url); hwr.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; It’s not necessary to manually add the Accept-Encoding HTTP header; it will automatically be added when that property is used. (Also, I know this is just example code, but the HttpWebResponse object should be placed in a using block … Read more

C# HttpWebRequest The underlying connection was closed: An unexpected error occurred on a send

In 4.0 version of the .Net framework the ServicePointManager.SecurityProtocol only offered two options to set: Ssl3: Secure Socket Layer (SSL) 3.0 security protocol. Tls: Transport Layer Security (TLS) 1.0 security protocol In the next release of the framework the SecurityProtocolType enumerator got extended with the newer Tls protocols, so if your application can use th … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)