Created
March 29, 2017 09:35
-
-
Save ahelland/28aed86728831d52299501a7e2be32c2 to your computer and use it in GitHub Desktop.
API Playground - C#
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
[HttpPost] | |
public async Task<IActionResult> CSharp(Code code) | |
{ | |
string output = code.csx; | |
var apiURL = "https://www.microsoft.com/net/api/code"; | |
using (var client = new HttpClient()) | |
{ | |
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, new Uri(apiURL)); | |
request.Headers.Add("Referer", "https://www.microsoft.com/net"); | |
var codeSnippet = code.csx; | |
var codeInput = new CodeRequest { language = "csharp", captureStats = false, sources = new string[1] }; | |
codeInput.sources[0] = codeSnippet; | |
var request_content = JsonConvert.SerializeObject(codeInput); | |
request.Content = new StringContent(request_content, Encoding.UTF8, "application/json"); | |
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |
HttpResponseMessage response = await client.SendAsync(request); | |
var responseString = await response.Content.ReadAsStringAsync(); | |
var codeOutput = JsonConvert.DeserializeObject<CodeResponse>(responseString); | |
code.output = codeOutput.Output[0]; | |
} | |
return View(code); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what is res?