mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
Merge pull request #229 from NativeScript/http-headers-
http for android header values fixed and test added
This commit is contained in:
@ -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) {
|
export var test_request_jsonAsContentSentAndReceivedProperly = function (done) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ function buildJavaOptions(options: http.HttpRequestOptions) {
|
|||||||
var pair = com.tns.Async.Http.KeyValuePair;
|
var pair = com.tns.Async.Http.KeyValuePair;
|
||||||
|
|
||||||
for (var key in options.headers) {
|
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;
|
javaOptions.headers = arrayList;
|
||||||
|
@ -28,7 +28,7 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
|
|||||||
|
|
||||||
if (options.headers) {
|
if (options.headers) {
|
||||||
for (var header in options.headers) {
|
for (var header in options.headers) {
|
||||||
urlRequest.setValueForHTTPHeaderField(options.headers[header], header);
|
urlRequest.setValueForHTTPHeaderField(options.headers[header] + "", header);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user