|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
| 3 | +using System.IO; |
3 | 4 | using System.Linq; |
4 | 5 | using System.Net; |
5 | 6 | using System.Security.Cryptography.X509Certificates; |
| 7 | +using System.Text; |
6 | 8 | using Newtonsoft.Json.Linq; |
7 | 9 |
|
8 | 10 | namespace Nancy.Simple |
@@ -163,13 +165,25 @@ private static bool GetPlay(out int betValue, List<Tuple<string,string>> cards, |
163 | 165 | try |
164 | 166 | { |
165 | 167 | string address = "http://rainman.leanpoker.org/rank"; |
166 | | - string reply = null; |
167 | | - using (WebClient client = new WebClient()) |
168 | | - { |
169 | | - client.Headers.Add("Content-Type", "application/json"); |
170 | | - reply = client.UploadString(address, "cards=[\r\n {\"rank\":\"5\",\"suit\":\"diamonds\"},\r\n {\"rank\":\"6\",\"suit\":\"diamonds\"},\r\n {\"rank\":\"7\",\"suit\":\"diamonds\"},\r\n {\"rank\":\"7\",\"suit\":\"spades\"},\r\n {\"rank\":\"8\",\"suit\":\"diamonds\"},\r\n {\"rank\":\"9\",\"suit\":\"diamonds\"}\r\n]"); |
171 | | - Console.Error.WriteLine(reply); |
172 | | - } |
| 168 | + var http = (HttpWebRequest)WebRequest.Create(new Uri(address)); |
| 169 | + http.Accept = "application/json"; |
| 170 | + http.ContentType = "application/json"; |
| 171 | + http.Method = "POST"; |
| 172 | + |
| 173 | + string parsedContent = "cards=[{\"rank\":\"5\",\"suit\":\"diamonds\"},\r\n {\"rank\":\"6\",\"suit\":\"diamonds\"},\r\n {\"rank\":\"7\",\"suit\":\"diamonds\"},\r\n {\"rank\":\"7\",\"suit\":\"spades\"},\r\n {\"rank\":\"8\",\"suit\":\"diamonds\"}]"; |
| 174 | + ASCIIEncoding encoding = new ASCIIEncoding(); |
| 175 | + Byte[] bytes = encoding.GetBytes(parsedContent); |
| 176 | + |
| 177 | + Stream newStream = http.GetRequestStream(); |
| 178 | + newStream.Write(bytes, 0, bytes.Length); |
| 179 | + newStream.Close(); |
| 180 | + |
| 181 | + var response = http.GetResponse(); |
| 182 | + |
| 183 | + var stream = response.GetResponseStream(); |
| 184 | + var sr = new StreamReader(stream); |
| 185 | + var content = sr.ReadToEnd(); |
| 186 | + Console.Error.WriteLine(content); |
173 | 187 | } |
174 | 188 | catch (Exception ex) |
175 | 189 | { |
|
0 commit comments