Issue with Directions v2 POST

When running sample code in c# I get an error:

{
“error”: {
“message”: “Content type ‘text/plain;charset=utf-8’ not supported”
},

Hi @Grassyal,

see my answer to this post:

This works:

string authorization = "yourKey";
string responseContent = "";
string coords = "{\"coordinates\":[[8.681495,49.41461],[8.686507,49.41943],[8.687872,49.420318]]}";
Byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(coords);

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://api.openrouteservice.org/v2/directions/driving-car/geojson");
request.Method = "POST";
  
request.Accept = "application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8";
request.Headers.Add("Authorization", authorization);
request.ContentType = "application/json";
request.ContentLength = byteArray.Length;

System.IO.Stream reqStream = request.GetRequestStream();
reqStream.Write(byteArray, 0, byteArray.Length);

using (System.Net.HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse)
{
    using (var reader = new StreamReader(response.GetResponseStream()))
    {
        responseContent = reader.ReadToEnd();
    }
}
2 Likes

Thanks a lot, i will adjust the example