-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy path_lib.request.js
52 lines (46 loc) · 1.17 KB
/
_lib.request.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
async function requestHtml(url, options) {
try {
let html = (await req(url, options)).content;
// log(html);
return html
} catch (e) {
log(`requestHtml error:${e.message}`);
return ''
}
}
async function requestJson(url, options) {
try {
let html = (await req(url, options)).content;
return JSON.parse(html)
} catch (e) {
log(`requestJson error:${e.message}`);
return {}
}
}
async function getPublicIp() {
let ip_obj = await requestJson('http://httpbin.org/ip');
// log('ip_obj:',ip_obj);
return ip_obj.origin
}
async function getHtml(config) {
try {
return await axios.request(typeof config === "string" ? config : {
url: config.url,
method: config.method || 'GET',
headers: config.headers || {
'User-Agent': PC_UA
},
data: config.data || '',
responseType: config.responseType || '',//'arraybuffer'
})
} catch (e) {
return e.response
}
}
$.exports = {
requestHtml,
requestJson,
getPublicIp,
getHtml
// axios // 没法import系统库
}