本文整理匯總了TypeScript中tns-core-modules/http.request函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript request函數的具體用法?TypeScript request怎麽用?TypeScript request使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了request函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
export var test_request_responseStatusCodeShouldBeDefined = function (done) {
var result: http.HttpResponse;
// >> http-get-response
http.request({ url: "https://httpbin.org/get", method: "GET" }).then(function (response) {
//// Argument (response) is HttpResponse!
var statusCode = response.statusCode;
// >> (hide)
result = response;
try {
TKUnit.assert(typeof (result.statusCode) !== "undefined", "response.statusCode should be defined!");
done(null);
}
catch (err) {
done(err);
}
// << (hide)
}, function (e) {
//// Argument (e) is Error!
// >> (hide)
done(e);
// << (hide)
});
// << http-get-response
};
示例2: function
export var test_request_FormDataContentSentAndReceivedProperly = function (done) {
var result;
var data = new FormData();
data.append("MyVariableOne", "ValueOne");
data.append("MyVariableTwo", "ValueTwo");
http.request({
url: "https://httpbin.org/post",
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
content: data
}).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);
});
};
示例3: _setSrcProperty
private _setSrcProperty(value: string) {
if (value) {
value = value.trim();
let isUrl = false;
if (value.indexOf('://') !== -1) {
if (value.indexOf('res://') === -1) {
isUrl = true;
}
}
this._src = value;
if (!isUrl) {
const currentPath = knownFolders.currentApp().path;
if (value[1] === '/' && (value[0] === '.' || value[0] === '~')) {
value = value.substr(2);
}
if (value[0] !== '/') {
value = currentPath + '/' + value;
}
this._drawable = new pl.droidsonroids.gif.GifDrawable(value);
this.nativeView.setImageDrawable(this._drawable);
} else {
const requestOptions: any = { url: value, method: 'GET' };
if (this._headers !== null) {
requestOptions.headers = this._headers;
}
HttpRequest(requestOptions).then(
r => {
if (r.statusCode === 200) {
this._drawable = new pl.droidsonroids.gif.GifDrawable(
r.content.raw.toByteArray()
);
this.nativeView.setImageDrawable(this._drawable);
} else {
console.log('error getting image: ' + r.statusCode);
}
},
err => {
console.log(err);
}
);
}
} else {
console.log('No src property set for the Gif.');
}
}