Example POST request

4 posts / 0 new
Last post
CityGen3D
Example POST request

Hi,

I'm having problems in correctly formatting a POST data request for getting elevation data.

I basically just want to send a collection of Lat Lng points.

I've tried this (and variations of) for the data part of the POST request:

{"latLngCollection":[51.1274005955122,1.33967065396542,51.1274005955122,1.34012873827139,51.1276880563853,1.33967065396542,51.1276880563853,1.34012873827139]}

but I get this error message back in the response: "Illegal argument from request. Error parsing JSON provided by HTTP Request"

I use this for the URL, which works as I get a response back (albeit with the error message in it)

http://open.mapquestapi.com/elevation/v1/profile?key=MYKEY

So I assume my error is with the POST data formatting.

Does anyone have an example POST data JSON request string that is known to work to help me to format the request correctly?

Thanks very much!


MQBrianCoakley
Here is how I did it with a

Here is how I did it with a curl command.

 

curl -d "json={latLngCollection:[51.1274005955122,1.33967065396542,51.1274005955122,1.34012873827139,51.1276880563853,1.33967065396542,51.1276880563853,1.34012873827139]}" "http://open.mapquestapi.com/elevation/v1/profile?key=KEY"

 

 

I hope this helps.


CityGen3D
Thanks for your reply.

Thanks for your reply.

I'm still getting the same error back from MapQuest, implying everything is basically fine other than the format of my request:
"Illegal argument from request. Error parsing JSON provided by HTTP Request"

I can only assume the issue is with how I'm attempting to initiate the POST request in Unity.

If anyone has got MapQuest Elevations to work in Unity I'd love to hear from you.

This is my code that gets the error:

string url = mapquestUrl + "?key=" + mapquestKey + "&outFormat=xml";
string strCoords = "json={latLngCollection:[51.1274005955122,1.33967065396542,51.1274005955122,1.34012873827139,51.1276880563853,1.33967065396542,51.1276880563853,1.34012873827139]}"

List<IMultipartFormSection> formData = new List<IMultipartFormSection>();
formData.Add(new MultipartFormDataSection(strCoords));

UnityWebRequest webRequest = UnityWebRequest.Post(url, formData);
yield return webRequest.SendWebRequest();

I can then see the returned file from MapQuest with the error in it in webRequest.downloadHandler.text

My next attempt will be to try a simple test using the GET method, although that's not a long term solution as I want to query quite a lot of points in a single request.
So if anyone has got a POST Elevations request to work in Unity I'd love to hear from you. I suspect I'm not setting it up properly (headers?) so MapQuest can't parse the input JSON.


MQBrianCoakley
Using Postman, I removed the
Using Postman, I removed the "json=" part and it worked as expected.