Initial commit
This commit is contained in:
56
ConsoleApp1/Program.cs
Normal file
56
ConsoleApp1/Program.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
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();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user