Merge pull request #229 from NativeScript/http-headers-

http for android header values fixed and test added
This commit is contained in:
Vladimir Enchev
2015-03-30 10:55:47 +03:00
3 changed files with 25 additions and 2 deletions

View File

@ -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;

View File

@ -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;

View File

@ -28,7 +28,7 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
if (options.headers) {
for (var header in options.headers) {
urlRequest.setValueForHTTPHeaderField(options.headers[header], header);
urlRequest.setValueForHTTPHeaderField(options.headers[header] + "", header);
}
}