GET /api/gpx.php?scenario=0
Host: 192.168.2.144:8080
Accept: application/json
Accept-Language: en-us
Connection: keep-alive
Accept-Encoding: gzip, deflate
User-Agent: ConnectMobile/2 CFNetwork/808.2.16 Darwin/16.3.0
I think this is pretty good evidence that gzip and deflate encodings are supported. I would be very surprised that the Accept header would be getting sent if the platform didn't support those encodings.
My test case generates requests in several different ways trying to reproduce the problem with the question mark getting appended to the url. I'm not able to reproduce the problem at all. Unfortunately, I don't have access to an Android device to test with, so I leave this to you if you're interested in taking it that far.
Here is the source for my python test program.
import BaseHTTPServer
import json
class MockRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def init(self):
pass
def do_GET(self):
print self.command, self.path
print self.headers
message_body = json.dumps({ "result" : "success" })
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", len(message_body))
self.end_headers()
self.wfile.write(message_body)
def _main():
server_address = ('', 8080)
httpd = BaseHTTPServer.HTTPServer(server_address, MockRequestHandler)
httpd.serve_forever()
if __name__=='__main__':
_main()
Here is the source code for my client program.
using Toybox.Application as App;
using Toybox.Lang as Lang;
using Toybox.System as Sys;
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
using Toybox.Communications as Comm;
var _G_code;
var _G_data;
var _G_pending = false;
class XBehaviorDelegate extends Ui.BehaviorDelegate
{
function initialize() {
BehaviorDelegate.initialize();
}
const _scenarios = [
{
:url => "http://192.168.2.144:8080/api/gpx.php?scenario=0",
:params => null,
:headers => {
}
},
{
:url => "http://192.168.2.144:8080/api/gpx.php?scenario=1",
:params => {
},
:headers => {
}
},
{
:url => "http://192.168.2.144:8080/api/gpx.php",
:params => {
"scenario" => "2"
},
:headers => {
}
},
{
:url => "http://192.168.2.144:8080/api/gpx.php?scenario=3",
:params => null,
:headers => {
"Content-Type" => Comm.REQUEST_CONTENT_TYPE_URL_ENCODED
}
},
{
:url => "http://192.168.2.144:8080/api/gpx.php?scenario=4",
:params => {
},
:headers => {
"Content-Type" => Comm.REQUEST_CONTENT_TYPE_URL_ENCODED
}
},
{
:url => "http://192.168.2.144:8080/api/gpx.php",
:params => {
"scenario" => "5"
},
:headers => {
"Content-Type" => Comm.REQUEST_CONTENT_TYPE_URL_ENCODED
}
}
];
hidden var _M_mode = 0;
function onSelect() {
if (!_G_pending) {
_G_pending = true;
_G_code = "";
var scenario = _scenarios[_M_mode];
_M_mode = (_M_mode + 1) % _scenarios.size();
var url = scenario[:url];
var params = scenario[:params];
var headers = scenario[:headers];
headers.put("Accept", "application/json");
var options = {
:headers => headers,
:method => Comm.HTTP_REQUEST_METHOD_GET,
:responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON
};
Comm.makeWebRequest(url, params, options, method(:onWebResponse));
Ui.requestUpdate();
}
return true;
}
function onWebResponse(code, data) {
_G_pending = false;
_G_code = code;
_G_data = data;
Ui.requestUpdate();
}
}
class XView extends Ui.View
{
function initialize() {
View.initialize();
}
function onUpdate(dc) {
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_BLACK);
dc.clear();
var cy = dc.getHeight() / 2;
var cx = dc.getWidth() / 2;
var color = Gfx.COLOR_GREEN;
if (_G_pending) {
color = Gfx.COLOR_RED;
}
dc.setColor(color, color);
dc.fillCircle(cx, 10, 7);
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_BLACK);
if (_G_code != null) {
var fy = dc.getFontHeight(Gfx.FONT_LARGE);
dc.drawText(cx, cy - fy, Gfx.FONT_LARGE, _G_code.toString(), Gfx.TEXT_JUSTIFY_CENTER);
if (_G_data != null) {
dc.drawText(cx, cy, Gfx.FONT_XTINY, _G_data.toString(), Gfx.TEXT_JUSTIFY_CENTER);
}
}
}
}
class XApp extends App.AppBase
{
function initialize() {
AppBase.initialize();
}
function getInitialView() {
return [ new XView(), new XBehaviorDelegate() ];
}
}
In looking at the output you posted previously, I'm wondering if the 0 that appears at the end of the trace output was the response body. If it is, that is most likely why you were getting an error response code. If the response can't be interpreted as a JSON object, you'll get an error.
Travis