From f9cc37bc1531d82650049496174ff581aac6871f Mon Sep 17 00:00:00 2001 From: corylulu Date: Wed, 18 Jan 2017 15:22:00 -0800 Subject: [PATCH] Fixed long response times for requests made to reddit Reddit servers seem to throw a fit if you don't specify both a `UserAgent` and an `AcceptLanguage` in the requests. For me, this results in very long responses that took 5-10 seconds for a request. Using Fiddler, I was able to determine that the timeout was taking place between `ServerGotRequest` and `ServerBeginResponse`, so that's when I tried modifying the header until I pinpointed what was causing the long delays. If others are having similar delays as me, this change makes a world of difference. --- RedditSharp/WebAgent.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RedditSharp/WebAgent.cs b/RedditSharp/WebAgent.cs index 07cfb4c..5892c1a 100644 --- a/RedditSharp/WebAgent.cs +++ b/RedditSharp/WebAgent.cs @@ -240,6 +240,7 @@ public virtual HttpWebRequest CreateRequest(string url, string method) } request.Method = method; request.UserAgent = UserAgent + " - with RedditSharp by /u/sircmpwn"; + request.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.8"); return request; } @@ -259,6 +260,7 @@ protected virtual HttpWebRequest CreateRequest(Uri uri, string method) } request.Method = method; request.UserAgent = UserAgent + " - with RedditSharp by /u/sircmpwn"; + request.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.8"); return request; }