static void Main(string[] args) { SendMessageRequest req = new SendMessageRequest.Builder() .SetAccessToken("test_token") .SetFrom("jackie") .SetTo("good") .SetText("Hello every one,I'm Jackie Lee.") .SetTopic("STN Discuss") .Build(); byte[] buffer = req.ToByteArray(); HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:8080/"); ByteArrayContent content = new ByteArrayContent(buffer); content.Headers.Add("Content-Type", "application/octet-stream"); Stream respStream = client.PostAsync("mars/sendmessage", content).Result.Content.ReadAsStreamAsync().Result; SendMessageResponse resp = SendMessageResponse.ParseFrom(respStream); Console.Read(); }
static SendMessageRequest GetReq() { SendMessageRequest req = new SendMessageRequest.Builder() .SetAccessToken("test_token") .SetFrom("Jackie") .SetTo("all") .SetText("Hello,everyone.") .SetTopic("how to check a test").Build(); return(req); }
static void SendMessage(BufferConnection bc, string msg) { SendMessageRequest req = new SendMessageRequest.Builder() .SetAccessToken("test_token") .SetFrom("jackie") .SetTo("all") .SetText(msg) .SetTopic("STN Discuss") .Build(); msgXp.cmdId = CMD_ID_SEND_MESSAGE_VALUE; msgXp.body = req.ToByteArray(); byte[] toSendBuf = msgXp.encode(); bc.Send(toSendBuf); }