Browse code

wanabe fix for the .NET version

Pierre-David BeĢlanger authored on 21/09/2015 21:41:38
Showing 1 changed files
... ...
@@ -71,7 +71,11 @@ namespace ChatterBotAPI
71 71
             request.ContentType = "text/html";
72 72
             request.CookieContainer = container;
73 73
 
74
-            request.GetResponse();
74
+			var response = (HttpWebResponse)request.GetResponse();
75
+			using (var responseStreamReader = new StreamReader(response.GetResponseStream()))
76
+			{
77
+				responseStreamReader.ReadToEnd ();
78
+			}
75 79
 
76 80
             return container.GetCookies(request.RequestUri);
77 81
         }
... ...
@@ -95,13 +99,17 @@ namespace ChatterBotAPI
95 99
             request.ContentType = "application/x-www-form-urlencoded";
96 100
             request.ContentLength = postDataBytes.Length;
97 101
 
98
-            var outputStream = request.GetRequestStream();
99
-            outputStream.Write(postDataBytes, 0, postDataBytes.Length);
100
-            outputStream.Close();
101
-
102
-            var response = (HttpWebResponse)request.GetResponse();
103
-            var responseStreamReader = new StreamReader(response.GetResponseStream());
104
-            return responseStreamReader.ReadToEnd().Trim();
102
+			using (var outputStream = request.GetRequestStream())
103
+			{
104
+				outputStream.Write(postDataBytes, 0, postDataBytes.Length);
105
+				outputStream.Close();
106
+
107
+				var response = (HttpWebResponse)request.GetResponse();
108
+				using (var responseStreamReader = new StreamReader(response.GetResponseStream()))
109
+				{
110
+					return responseStreamReader.ReadToEnd().Trim();
111
+				}
112
+			}
105 113
         }
106 114
 
107 115
         public static string XPathSearch(string input, string expression)