From 79fb7e2a343d86fc72edf3aa2145d08bcc0bdf1d Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Mon, 30 Mar 2015 09:42:12 +0300 Subject: [PATCH] http for android header values fixed and test added --- apps/tests/http-tests.ts | 23 +++++++++++++++++++++++ http/http-request.android.ts | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/apps/tests/http-tests.ts b/apps/tests/http-tests.ts index 682be7cb4..53a3711d8 100644 --- a/apps/tests/http-tests.ts +++ b/apps/tests/http-tests.ts @@ -340,6 +340,29 @@ export var test_request_contentSentAndReceivedProperly = function (done) { }); }; +export var test_request_NonStringHeadersSentAndReceivedProperly = function (done) { + var result; + + var postData = "MyVariableOne=ValueOne&MyVariableTwo=ValueTwo"; + + http.request({ + url: "https://httpbin.org/post", method: "POST", + headers: { "Content-Type": "application/x-www-form-urlencoded", "Content-Length": postData.length }, + content: postData + }).then(function (response) { + result = response.content.toJSON(); + try { + TKUnit.assert(result["form"]["MyVariableOne"] === "ValueOne" && result["form"]["MyVariableTwo"] === "ValueTwo", "Content not sent/received properly!"); + done(null); + } + catch (err) { + done(err); + } + }, function (e) { + done(e); + }); +}; + export var test_request_jsonAsContentSentAndReceivedProperly = function (done) { var result; diff --git a/http/http-request.android.ts b/http/http-request.android.ts index 3be665917..732255c6c 100644 --- a/http/http-request.android.ts +++ b/http/http-request.android.ts @@ -85,7 +85,7 @@ function buildJavaOptions(options: http.HttpRequestOptions) { var pair = com.tns.Async.Http.KeyValuePair; for (var key in options.headers) { - arrayList.add(new pair(key, options.headers[key])); + arrayList.add(new pair(key, options.headers[key] + "")); } javaOptions.headers = arrayList;