mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-10 23:59:42 +08:00
31 lines
720 B
JavaScript
31 lines
720 B
JavaScript
let request = async (verb, url, body, callback) => {
|
|
if (typeof body === "function") {
|
|
callback = body;
|
|
body = null;
|
|
}
|
|
|
|
var headers = {
|
|
"Accept": "application/json",
|
|
"Content-Type": "application/json"
|
|
};
|
|
|
|
if (body && typeof body === "object") {
|
|
body = JSON.stringify(body);
|
|
}
|
|
|
|
try {
|
|
var statusCode;
|
|
let response = await fetch(url, {
|
|
method: verb,
|
|
headers: headers,
|
|
body: body
|
|
});
|
|
|
|
let statusCode = response.status;
|
|
let body = await response.text();
|
|
callback(null, {statusCode: statusCode, body: body});
|
|
} catch (err) {
|
|
callback(err);
|
|
}
|
|
}
|