private async void buttonTestOpenRouteService_ClickAsync(object sender, EventArgs e)
{
//Common testing requirement. If you are consuming an API in a sandbox/test region, uncomment this line of code ONLY for non production uses.
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
//Be sure to run "Install-Package Microsoft.Net.Http" from your nuget command line.
var baseAddress = new Uri("https://api.openrouteservice.org");
using (var httpClient = new HttpClient { BaseAddress = baseAddress })
{
httpClient.DefaultRequestHeaders.Clear();
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8");
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "5b3 .. c5");
using (var content = new StringContent("{\"coordinates\":[[8.678,49.551],[8.502,49.531]],\"attributes\":[\"avgspeed\",\"percentage\",\"detourfactor\"],\"elevation\":\"true\",\"extra_info\":[\"suitability\",\"surface\",\"waycategory\",\"waytype\",\"traildifficulty\",\"osmid\",\"countryinfo\"],\"instructions_format\":\"html\",\"language\":\"de\",\"preference\":\"recommended\"}", Encoding.UTF8, "application/json"))
{
using (var response = await httpClient.PostAsync("/v2/directions/cycling-regular/json", content))
{
string responseData = await response.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject(responseData);
}
}
}
}
And inside the designer ( it’s a winforms application):
this.buttonTestOpenRouteService.Click += new System.EventHandler(this.buttonTestOpenRouteService_ClickAsync);
Some update on the template: I did add some of your changes, but the escaping of the backslashes sadly didn’t work. I added a comment, to escape quotes.
In a bit more detail: We use a highlighting plugin for the different code templates for readability. Before the template is passed, the quotes actually are escaped. But after beautifying it, escaped quotes are replaced by normal ones There is a setting to disable this which had no effect.
To further look into this is not really worth the outcome right now.
I know it should be a one click running template, but it has to stay like this for now.
We are using the vue-markdown component to render the templates and PrismJS for highlighting if someone wants to investigate this.