Advertisement
Guest User

Untitled

a guest
Jan 15th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1.   public PrintResponse Send(Request data, Konfiguration config)
  2.         {
  3.             Uri uri = new Uri($"{BaseAddress}/Api/Send");
  4.          
  5.             var content = new FormUrlEncodedContent(new[]
  6.             {
  7.                 new KeyValuePair<string, string>("data", JsonConvert.SerializeObject(data)),
  8.                 new KeyValuePair<string, string>("config", JsonConvert.SerializeObject(config))
  9.             });
  10.  
  11.             return CallApiMethod<PrintResponse>(uri, encodedContent);
  12.         }
  13.  
  14.  
  15.     public T CallApiMethod<T>(Uri uri, StringContent content)
  16.         {
  17.             var response = client.PostAsync(uri, content).GetAwaiter().GetResult();
  18.             var responseContent = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
  19.             if (!response.IsSuccessStatusCode)
  20.             {
  21.                 throw new Exception(responseContent);
  22.             }
  23.  
  24.         }
  25.  
  26.  
  27.  
  28.         [HttpPost]
  29.         public Response Send([FromBody] JObject data)
  30.         {
  31.          
  32.             Request Request = null;
  33.             if (data["data"] != null)
  34.             {
  35.                Request = JsonConvert.DeserializeObject<Request>(data["data"].ToString());
  36.             }
  37.  
  38.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement