Last active
October 26, 2020 10:11
-
-
Save AvgustPol/8e14a07862ae5d804b8b7a10398c681d to your computer and use it in GitHub Desktop.
WebClient cheatsheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string HttpGet<T>(string url, string publicAccessToken) | |
{ | |
using (WebClient wc = new WebClient()) | |
{ | |
wc.Headers.Add("Authorization", $"Basic {publicAccessToken}"); | |
string reply = await wc.DownloadStringTaskAsync(url); | |
var result = JsonConvert.DeserializeObject<T>(reply); | |
return result; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string HttpPost<T>(string url, T object) | |
{ | |
using (WebClient wc = new WebClient()) | |
{ | |
string objectApi = JsonConvert.SerializeObject(object); | |
wc.QueryString.Add("body", objectApi); | |
// POST | |
var data = wc.UploadString(url, objectApi); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment