makeWebRequest problem for XML, okay JSON

Former Member
Former Member
I have used a lot time on trial-and-error for the makeWebRequest function. Using a very simple service it works for JSON, but not for XML.

var url = "www.broadbandmap.gov/.../nation";
// WORKS
Comm.makeWebRequest(url, {"format" => "json"}, {}, method(:onReceive));
// FAILS for XML with responseCode "Failed to load Error: -400"
Comm.makeWebRequest(url, {}, {}, method(:onReceive));


For the XML scenario I have tried all sorts of different options, but always fails. Anyone who can make an working example?
  • The makeWebRequest() method currently handles JSON and URL encoded response data. Have a look at the documentation for the :responseType parameter...

    :responseType (Number) — The format of the response. Should be a HTTP_RESPONSE_CONTENT_TYPE_* value. If not given, the system will attempt to first parse the response as JSON, then as URL ENCODED.


    It seems possible that support for xml could be added in the future, but it isn't there now. Your options are to form your request so you always get a response in a supported format, or to write an intermediary service to translate to one of the supported formats.

    Travis
  • Former Member
    Former Member over 9 years ago
    Public service available for XML to JSON ?

    Thank you for your answer. Then I don't have to "waste" anymore time on that issue. Do you know if there is a public "service" available that transfer from XML to JSON. Otherwise I guess I have to look into hosted cloud based solutions, but then I have to pay for hosting etc..
  • I don't. I do know that you can write your own service and host it in google app engine for free, provided that your service stays below their thresholds for a free service.

    Travis
  • Former Member
    Former Member over 9 years ago
    Cloud hosting

    Thx for you suggestion. Looks like I have to pay for outbound network traffic, so think I will go for Azure
    https://azure.microsoft.com/en-us/pricing/details/app-service/

    Now I only need some time to code, deploy and test.
  • Not trying to change your mind, just making sure you have accurate information... Google AppEngine allows you to use 1GB/day outgoing before you'd need to worry about billing. Information on quotas can be found here.
  • Former Member
    Former Member over 9 years ago
    Also wouldn't hurt to ask the xml service provider if they could also provide data in JSON.
  • Former Member
    Former Member over 9 years ago
    Currently not prioritized

    Also wouldn't hurt to ask the xml service provider if they could also provide data in JSON.


    Had the same thought, but they responded with "Currently not prioritized". Hope they will soon...
  • Apparently this is still the case? It's a bit annoying when the response has a Content-Type: text/xml and I see the data in the simulator Http Traffic Logs but no way to get at it :-/

  • Starting with CIQ 3.0.0 there is HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN,

  • Yes, you can lie to the system and tell it that the data is TEXT_PLAIN (as suggested by ), but you'll have access to the raw XML data as a String. You will have to parse the XML in MonkeyC. I can almost guarantee that this will not be pleasant.

    I'll re-iterate.. assuming that the service provider doesn't provide a way to get the data in JSON format, the easiest way to solve this is to prop up a proxy service on Google App Engine, AWS Lambda, Heroku, or some other hosting provider. If you use python you can use xmljson to do the transform in just a few lines of code. Provided you don't exceed the limits for free applications (they are pretty generous as of the last time I looked), there would be no cost to you beyond development and maintenance time.