Last active
May 27, 2018 18:09
-
-
Save Scarsz/819c2e6be618fbe0d712e5c2984170d1 to your computer and use it in GitHub Desktop.
https://debug.scarsz.me C# example
This file contains 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
using System; | |
using System.Collections.Generic; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
using RestSharp; | |
namespace ScarszDebugTest | |
{ | |
internal static class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var files = new Dictionary<string, Dictionary<string, string>> | |
{ | |
{"1-file.txt", new Dictionary<string, string> {{"content", "file content 1"}}}, | |
{"2-other.stuff", new Dictionary<string, string> {{"content", "file content 2"}, {"description", "is .stuff an actually used extension?"}}} | |
}; | |
var payload = new | |
{ | |
description = "Greem sucks at C#", | |
files | |
}; | |
var payloadJson = JsonConvert.SerializeObject(payload); | |
var client = new RestClient("https://debug.scarsz.me"); | |
client.UserAgent = "SIVA/V1.5.1"; | |
var request = new RestRequest("post", Method.POST); | |
request.AddHeader("Content-Type", "application/json"); | |
request.RequestFormat = DataFormat.Json; | |
request.Parameters.Clear(); | |
request.AddParameter("application/json", payloadJson, ParameterType.RequestBody); | |
var responseJson = client.Execute(request); | |
var response = (JObject) JsonConvert.DeserializeObject(responseJson.Content); | |
Console.WriteLine("Sent: " + payloadJson); | |
Console.WriteLine("Recieved: " + responseJson.StatusCode.GetHashCode() + " " + responseJson.StatusCode + " " + responseJson.Content.Trim()); | |
Console.WriteLine("Parsed: url=" + response.GetValue("url") + " allowance=" + response.GetValue("allowance")); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment