forked from crossutility/Quantumult-X
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample-task.js
More file actions
28 lines (24 loc) · 745 Bytes
/
sample-task.js
File metadata and controls
28 lines (24 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* @fileoverview Example to compose HTTP reqeuest
* and handle the response. Same task shares context.
*
* @supported Quantumult X (v1.0.5-build166)
*/
var url = "https://example.com/";
var method = "POST";
var headers = {"Field": "test-header-param"};
var data = {"info": "abc"};
var myRequest = {
url: url,
method: method, // Optional, default GET.
headers: headers, // Optional.
body: JSON.stringify(data) // Optional.
};
$task.fetch(myRequest).then(response => {
// response.statusCode, response.headers, response.body
console.log(response.body);
$notify("Title", "Subtitle", response.body); // Success!
}, reason => {
// reason.error
$notify("Title", "Subtitle", reason.error); // Error!
});