Backward characters in GPX request

Hi,

when requesting a gpx file I get a string back that contains backwards characters, which are not part of the gpx specification. Can this be corrected?

Thank you, Thomas (Xcode 11.3, macOS 10.14)

“<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><gpx version=“1.0” creator=“openrouteservice” xmlns=“https://raw.githubusercontent.com/GIScience/openrouteservice-schema/master/gpx/v2/ors-gpx.xsd”>openrouteservice directionsThis is a directions instructions file as GPX, generated from openrouteserviceopenrouteservice<email id=“support” domain=“openrouteservice.org”/><link href=“https://openrouteservice.org/”>https://openrouteservice.org/text/html<copyright author=“openrouteservice.org | OpenStreetMap contributors”>2020LGPL 3.02020-04-15T06:37:25.525Z<bounds maxLat=“45.677881” maxLon=”-109.924448" minLat=“42.862926” minLon="-111.016644"/><rtept lat=“45.675217” lon="-111.010676">1466.5East Main Street, I 90 Business, US 191, MT 84Head west on East Ma"…

Hi @t2null,

this is not a problem of the ors api.
i just did a quick curl request to check:

  %   curl -X POST \                                                                                                                                                         !10028
>   'https://api.openrouteservice.org/v2/directions/driving-car/gpx' \
>   -H 'Content-Type: application/json; charset=utf-8' \
>   -H 'Accept: application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8' \
>   -H 'Authorization: xxx' \
>   -d '{"coordinates":[[8.681495,49.41461],[8.686507,49.41943],[8.687872,49.420318]]}'
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><gpx version="1.0" creator="openrouteservice" xmlns="https://raw.githubusercontent.com/GIScience/openrouteservice-schema/master/gpx/v2/ors-gpx.xsd"><metadata><name>openrouteservice directions</name><desc>This is a directions instructions file as GPX, generated from openrouteservice</desc><author><name>openrouteservice</name><email id="support" domain="openrouteservice.org"/><link href="https://openrouteservice.org/"><text>https://openrouteservice.org/</text><type>text/html</type></link></author><copyright author="openrouteservice.org | OpenStreetMap contributors"><year>2020</year><license>LGPL 3.0</license></copyright><time>2020-04-15T08:47:32.841Z</time><bounds maxLat="49.420514" maxLon="8.690123" minLat="49.41461" minLon="8.681436"/><extensions><system-message></system-message></extensions></metadata><rte><rtept lat="49.41461" lon="8.681496"><name>Wielandtstraße</name><desc>Head north on Wielandtstraße</desc><extensions><distance>413.4</distance><duration>99.2</duration><type>11</type><step>0</step></extensions></rtept><rtept lat="49.414711" lon="8.68149"><name>Wielandtstraße</name><desc>Head

This might be introduced by your way of requesting our api. Are you still using Swift?
Maybe there is some parameter you can tweak for this. Otherwise you need to write a wrapper function to remove the escape slashes before continuing working with the response.

Best regards

Figured it out. The Swift example code encodes the data:

let task = URLSession.shared.dataTask(with: request) { data, response, error in
  if let response = response, let data = data {
    print(response)
    print(String(data: data, encoding: .utf8))
  } else {
    print(error)
  }
}

When I decoded the data there were no backward slashes.

    let task = URLSession.shared.dataTask(with: request) { data, response, error in
        if let response = response, let data = data {
            print(response)
                            
            let str = String(decoding: data, as: UTF8.self)
            print (str)
        } else {
            print(error)
        }
    }

You may want to update the Swift example for POST gpx.

Thank you, Thomas

Thank you very much for the working example!
Will update as soon as i have some time at my hands.

Best regards

@t2null The example was changed according to your suggestions.
Best regards