-
Notifications
You must be signed in to change notification settings - Fork 0
/
AuthenticatedPostRequest.cs
26 lines (25 loc) · 1.04 KB
/
AuthenticatedPostRequest.cs
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
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 osu.API.Requests {
public abstract class AuthenticatedPostRequest<T> : AuthenticatedRequest<T> {
public AuthenticatedPostRequest(string accessToken) : base(accessToken) {
}
public async Task<T> PostAsync(HttpClient client) {
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken);
var json = JsonConvert.SerializeObject(Headers);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var responseMessage = await client.PostAsync(RequestUrl, content);
if (responseMessage.IsSuccessStatusCode) {
var response = await responseMessage.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<T>(response);
}
return default(T);
}
}
}