|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using Newtonsoft.Json.Linq;
- using System;
- using System.Net;
- using System.Net.Http.Json;
- using System.Text;
-
- namespace Server
- {
- class HttpSender
- {
- private string url;
- private string token;
- public HttpSender(string url, string token)
- {
- this.url = url;
- this.token = token;
- }
-
- // void Test()
- // {
- // this.SendHttpRequest(new()).Wait();
- // }
- public async Task SendHttpRequest(int[] scores)
- {
- try
- {
- var request = new HttpClient();
- request.DefaultRequestHeaders.Authorization = new("Bearer", token);
- using (var response = await request.PutAsync(url, JsonContent.Create(new
- {
- result = new TeamScore[]
- {
- new TeamScore() { team_id = 0, score = scores[0], },
- new TeamScore() { team_id = 1, score = scores[1], },
- },
- mode = 0
- })))
- {
- Console.WriteLine("Send to web successfully!");
- Console.WriteLine($"Web response: {await response.Content.ReadAsStringAsync()}");
- }
- }
- catch (Exception e)
- {
- Console.WriteLine("Fail to send msg to web!");
- Console.WriteLine(e);
- }
- }
- }
-
- internal class TeamScore
- {
- public int team_id { get; set; } = 0;
- public int score { get; set; } = 0;
- }
- }
|