Skip to content

Commit 96a6577

Browse files
committed
Added rainman
1 parent 0e062ae commit 96a6577

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

‎src/PokerPlayer.cs‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Net;
56
using System.Security.Cryptography.X509Certificates;
7+
using System.Text;
68
using Newtonsoft.Json.Linq;
79

810
namespace Nancy.Simple
@@ -163,13 +165,25 @@ private static bool GetPlay(out int betValue, List<Tuple<string,string>> cards,
163165
try
164166
{
165167
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);
173187
}
174188
catch (Exception ex)
175189
{

0 commit comments

Comments
 (0)