Lunch break session February 24th 2014 at Trifork, Aarhus.
@filip_woj check it out: https://t.co/KgIRPf5XcM
— Glenn Block (@gblock) February 28, 2013
@powershell -NoProfile -ExecutionPolicy Unrestricted -Command "iex ((New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin
cinst scriptcs
using ... namespace ScriptCs.Request { public class Request : IScriptPackContext { public HttpResponseMessage PostJson<T>(string url, T objectToPost) where T : class { var httpClient = new HttpClient(); var bodyContent = new StringContent(JsonConvert.SerializeObject(objectToPost), Encoding.UTF8, "application/json"); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); return httpClient.PostAsync(url, bodyContent).Result; } } }
namespace ScriptCs.Request { public class ScriptPack : IScriptPack { IScriptPackContext IScriptPack.GetContext() { //context to be used in scripts return new Request(); } void IScriptPack.Initialize(IScriptPackSession session) { session.AddReference("System.Net.Http"); session.ImportNamespace("System.Net.Http"); session.ImportNamespace("Newtonsoft.Json"); } void IScriptPack.Terminate() { //Cleanup any resources here } } }