-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWSHttpClient.cs
More file actions
48 lines (42 loc) · 1.56 KB
/
Copy pathWSHttpClient.cs
File metadata and controls
48 lines (42 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using ClassLibrary2;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace WebServicesTest
{
public class WSHttpClient
{
public void Test(int choix)
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (choix == 1)
{
var response = client.GetAsync("http://localhost:52484/api/Product").Result;
Console.WriteLine(response);
}
else if(choix==2)
{
var response = client.GetAsync("http://localhost:52484/api/OrderJson").Result;
Console.WriteLine(response);
}
else if (choix == 3)
{
OrderSet order = new OrderSet();
order.Date = DateTime.Now;
order.IsCanceled = false;
order.Note = "Commande de produits";
order.SupplierNumber = "45114";
order.TotalOfOrderLine = 2;
StringContent content = new StringContent(JsonConvert.SerializeObject(order), Encoding.UTF8, "application/json");
var response = client.PostAsync("http://localhost:52484/api/OrderJson",content).Result;
Console.WriteLine(response);
}
}
}
}