You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.6 KiB
57 lines
1.6 KiB
using System;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using MyModels;
|
|
using System.Threading.Tasks;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Web;
|
|
|
|
namespace ConsoleApp1
|
|
{
|
|
class Program
|
|
{
|
|
static HttpClient client = new HttpClient();
|
|
private const string URL = "http://localhost/CoreWebAPI1/api/";
|
|
private const string DATA = @"{""object"":{""name"":""Name""}}";
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
//var builder = new UriBuilder(URL);
|
|
//var query = HttpUtility.ParseQueryString(builder.Query);
|
|
//query["ApiKey"] = "BgWSbwCNM3pEiCxgIlDEyD7HFpUgKPeL8OPDqH9nx";
|
|
//builder.Query = query.ToString();
|
|
//client.BaseAddress = new Uri(builder.ToString());
|
|
var client = new HttpClient();
|
|
string apikey = "BgWSbwCNM3pEiCxgIlDEyD7HFpUgKPeL8OPDqH9nx";
|
|
client.DefaultRequestHeaders.Add("ApiKey", apikey);
|
|
|
|
|
|
//client.PutAsync<User>(u)
|
|
client.BaseAddress = new Uri(URL);
|
|
var responseTask = client.GetAsync("user");
|
|
responseTask.Wait();
|
|
var result = responseTask.Result;
|
|
if (result.IsSuccessStatusCode)
|
|
{
|
|
|
|
var readTask = result.Content.ReadAsAsync<User[]>();
|
|
readTask.Wait();
|
|
|
|
var users = readTask.Result;
|
|
|
|
foreach (var User in users)
|
|
{
|
|
Console.WriteLine(User.LastName);
|
|
}
|
|
}
|
|
|
|
Console.ReadLine();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|