using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RestWebServiceClient.Model;
using System.IO;
namespace RestWebServiceClient
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static string baseAddress = "https://app.hotelrunner.com/", urlContent = "api/v2/apps/infos/connected_channels?token=zMBMWdqbdox8zBQuXD3xOoCDZQLRkiCTIoczvTnZ&hr_id=106465043";
private void button1_Click(object sender, EventArgs e)
{
try
{
listBox1.Items.Clear();
baseAddress = textBox1.Text;
foreach (string line in File.ReadLines("gonder.txt"))
{
Task.Run(() => RunAsyncGet(line)); //
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//Task T2 = new Task(RunAsyncPOST);
//T2.Start();
//Task T3 = new Task(RunAsyncPUT);
//T3.Start();
//Task T4 = new Task(RunAsyncDELETE);
//T4.Start();
object locker1 = new object();
// http://localhost:60308/api/person/5
async void RunAsyncGet(string line)
{ // GET
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(baseAddress);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("aplication/json"));
string apiKey = "q7w7z2i1tnz0Zhed1IYfGUfth3exKW3j";
client.DefaultRequestHeaders.Add("X-Api-Key", apiKey);
HttpResponseMessage response = await client.GetAsync(line);
if (response.IsSuccessStatusCode)
{
// person person = await response.Content.ReadAsAsync<person>();
Object Deger = await response.Content.ReadAsAsync<Object>();
lock (locker1)
{
this.Invoke(new MethodInvoker(() =>
{
listBox1.Items.Add(baseAddress + line + "-> " + response.IsSuccessStatusCode);
}));
}
}
else
{
lock (locker1)
{
this.Invoke(new MethodInvoker(() =>
{
listBox1.Items.Add(baseAddress + line + "-> " + response.IsSuccessStatusCode);
}));
}
}
}
}
async void RunAsyncPOST()
{ // POST
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:60308/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("aplication/json"));
person p = new person();
p.id = 2;
p.ad = "RECEP";
p.soyad = "EMEÇ";
HttpResponseMessage response = await client.PostAsJsonAsync("api/person/3", p);
if (response.IsSuccessStatusCode)
{
Uri personURL = response.Headers.Location;
Console.WriteLine(personURL);
}
}
}
async void RunAsyncPUT()
{ // PUT güncellemek
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:60308/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("aplication/json"));
person p = new person();
p.id = 2;
p.ad = "RECEP22";
p.soyad = "EMEÇ";
HttpResponseMessage response = await client.PutAsJsonAsync("api/person/3", p);
if (response.IsSuccessStatusCode)
{
Uri personURL = response.Headers.Location;
Console.WriteLine(personURL);
}
}
}
async void RunAsyncDELETE()
{ // DELETE
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:60308/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("aplication/json"));
person p = new person();
p.id = 2;
p.ad = "RECEP22";
p.soyad = "EMEÇ";
HttpResponseMessage response = await client.DeleteAsync("api/person/13");
if (response.IsSuccessStatusCode)
{
Uri personURL = response.Headers.Location;
Console.WriteLine(personURL);
}
}
}
}
}