Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Http;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net.Http.Headers;
- namespace ClientApiJSON
- {
- public class Account
- {
- public string Login { get; set; }
- public string Password { get; set; }
- }
- class Program
- {
- static HttpClient client = new HttpClient();
- static async Task RunAsync()
- {
- client.BaseAddress = new Uri("http://localhost:63984//");
- client.DefaultRequestHeaders.Accept.Clear();
- client.DefaultRequestHeaders.Accept.Add(
- new MediaTypeWithQualityHeaderValue("application/json"));
- try
- {
- Account account = new Account
- {
- Login = "Jakis",
- Password = "InneFajneZajebisteDziala"
- };
- var url = await CreateAccountAsync(account);
- }
- catch(Exception e)
- {
- Console.WriteLine(e.Message);
- }
- }
- static async Task<Uri> CreateAccountAsync(Account account)
- {
- HttpResponseMessage response = await client.PostAsJsonAsync(
- "addaccount", account);
- response.EnsureSuccessStatusCode();
- // return URI of the created resource.
- return response.Headers.Location;
- }
- static void Main(string[] args)
- {
- RunAsync().GetAwaiter().GetResult();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement