本文整理汇总了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.');
}
}