public void UpdateWithPut(CityModel value) { Debug.WriteLine(value); }
public void PostCity(CityModel value) { Debug.WriteLine(value); }
public async Task TestHttpClientPost() { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:3956/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); string date = DateTime.UtcNow.ToString("u"); client.DefaultRequestHeaders.Add("Timestamp", date); //string token=CreateToken() // HTTP GET string uri = "/api/Values/PostCity"; string methodType = "POST"; string querystring = ""; string message = string.Join("\n", methodType, date, uri.ToLower(), querystring); string token = VerifyTransactionSN.ComputeHash(SecurityConfig.Password, message); Console.WriteLine(token); client.DefaultRequestHeaders.Add("Authentication", string.Format("{0}:{1}", SecurityConfig.Password, token)); string routingUrl = uri + "?" + querystring; var postmodel = new CityModel { CityShortName = "文山", IcaoCode = "ZPPP" }; var response = await client.PostAsJsonAsync(uri, postmodel); Assert.True(response.IsSuccessStatusCode); }; }