makeJsonRequest does not behave as documented

I'm having some troubles getting the makeJsonRequest() to behave properly. I am currently seeing two problems.

The first is that the HTTP response code is not being supplied as the first parameter to my callback. This issue has already been mentioned in this post. Not having access to the http response code is frustrating for me now, but it will be difficult or maybe even impossible to interact with other web services in the future.

The second is that the generated url string is not valid as the ampersands separating the query parameters have been escaped. As an example, consider the following code.

var url = "localhost:8080/.../daily";

var params = {
"q" => "Corvallis,OR",
"cnt" => "1",
"mode" => "json",
"units" => "metric"
};

var options = {
};

Comm.makeJsonRequest(url, params, options, method(:onWeatherData));


Executing that code against tcptunnel reports the following network traffic. Note the url string.

> 2014-11-10 22:05:53 tcptunnel: request from 127.0.0.1
> 2014-11-10 22:05:53 > GET /data/2.5/forecast/daily?cnt=1&q=Corvallis,OR&units=metric&mode=json HTTP/1.0
Host: localhost:8080
User-Agent: wxWidgets 2.x

HTTP/1.1 200 OK
Server: nginx
Date: Tue, 11 Nov 2014 06:04:39 GMT
Content-Type: text/html
Content-Length: 27
Connection: close
X-Source: back
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST

{"message":"","cod":"404"}


Additionally, I'm not seeing any real documentation for the options dictionary. I'm sure it is there to do something, but I'm not sure what.
  • Note that I do have a workaround for the query string problem. I can change the url to include the full query string and pass an empty parameter dictionary. If I do this I get the expected response.

    var url = "localhost:8080/.../daily

    var params = {
    };

    var options = {
    };

    Comm.makeJsonRequest(url, params, options, method(:onWeatherData));


    > 2014-11-10 22:08:31 tcptunnel: request from 127.0.0.1
    > 2014-11-10 22:08:31 > GET /data/2.5/forecast/daily?q=Corvallis,OR&cnt=1&mode=json&units=metric? HTTP/1.0
    Host: localhost:8080
    User-Agent: wxWidgets 2.x

    HTTP/1.1 200 OK
    Server: nginx
    Date: Tue, 11 Nov 2014 06:07:15 GMT
    Content-Type: application/json; charset=utf-8
    Content-Length: 435
    Connection: close
    X-Source: redis
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Credentials: true
    Access-Control-Allow-Methods: GET, POST

    {"cod":"200","message":0.2899,"city":{"id":"5720727","name":"Corvallis","coord":{"lon":-123.264,"lat":44.565},"country":"United States of America","population":0},"cnt":1,"list":[{"dt":1415646000,"temp":{"day":279.71,"min":278.18,"max":279.71,"night":278.18,"eve":279.71,"morn":279.71},"pressure":1009.68,"humidity":71,"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01n"}]," speed":5.78,"deg":48,"clouds":0}]}
  • Also note that there is an extra question mark at the end of the request if you don't supply any parameters in the request map.