How to use the request function from urllib
Find comprehensive JavaScript urllib.request code examples handpicked from public code repositorys.
GitHub: qiniu/nodejs-sdk
173 174 175 176 177 178 179 180 181
data.stream = requestForm; } else { data.headers['Content-Length'] = 0; } var req = urllib.request(requestURI, data, function (respErr, respBody, respInfo) { callbackFunc(respErr, respBody, respInfo); });
188
578
0
+ 8 other calls in file
GitHub: cnpm/npminstall
74 75 76 77 78 79 80 81 82 83 84
async function _get(url, options, retry, globalOptions, hasCache) { try { // let mock agent easy for unittest if (process.env.MOCK_AGENT) { return await urllib.request(url, options); } return await httpclient.request(url, options); } catch (err) { retry--;
64
476
17
+ 12 other calls in file
GitHub: mythsman/hexo-douban
22 23 24 25 26 27 28 29 30 31 32
}); } module.exports.syncFetch = async function (url, referer, timeout) { try { const {data} = await urllib.request(url, { method: 'GET', timeout: timeout, dataType: 'json', headers: {
52
337
0
281 282 283 284 285 286 287 288 289 290
var fileName = req.docManager.getCorrectName(title); var userAddress = req.docManager.curUserHostAddress(); req.docManager.historyPath(fileName, userAddress, true); urllib.request(fileUrl, {method: "GET"},function(err, data) { if (configServer.get("maxFileSize") < data.length || data.length <= 0) { // check if the file size exceeds the maximum file size res.writeHead(200, { "Content-Type": "application/json" }); res.write(JSON.stringify({ "error": "File size is incorrect" })); res.end();
84
95
37
+ 4 other calls in file
GitHub: alibaba/top
118 119 120 121 122 123 124 125 126 127
} args.sign = this.sign(args); type = type || 'GET'; var options = {type: type, data: args, agent: this.agent}; var that = this; urllib.request(that.REST_URL, options, function (err, buffer) { var data; if (buffer) { buffer = that._wrapJSON(buffer.toString()); try {
66
143
31
GitHub: alibaba-archive/ots
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
if (err) { return callback(err); } url = hostname + url; var body = params.join('&'); urllib.request(url, { content: body, type: 'POST', timeout: self.requestTimeout, agent: self.requestAgent
30
49
17
+ 5 other calls in file
GitHub: COVESA/iot-event-analytics
439 440 441 442 443 444 445 446 447 448
writeStream: file, consumeWriteStream: true, followRedirect: true }; log.trace(`Download Options: ${JSON.stringify(dlOptions)}`); urllib.request(dlURL.toString(), dlOptions, function (err, data, res) { log.info('Download finished, installing Visual Studio Code extension'); let installOutput; try { installOutput = execSync(`code --install-extension ${filename} --force`,
15
27
0
119 120 121 122 123 124 125 126 127 128
data: data, headers: {}, }; var req = {url: url, params: params}; req = self.setAuthentication(req); urllib.request(req.url, req.params, function (err, resData, res) { debug('%s %s %j: status: %s, resData: %d bytes, err: %j', method, url, data, res && res.statusCode, resData && resData.length || 0, err); self.handleResult(method, err, resData, res, function (err, result) {
6
6
10
+ 29 other calls in file
138 139 140 141 142 143 144 145 146 147
"Content-Type": "application/json", "charset": "utf-8" } }; // console.log('pkg', JSON.stringify(pkg)) urllib.request(URLS_SEND + appid, pkg, function (err, data, res) { if (err) return callback(err); // console.log(data.toString()); that.validate(data.toString(), appid, callback); });
1
0
0
GitHub: popomore/findlinks
86 87 88 89 90 91 92 93 94 95
} } } async _getHTML(url) { const ret = await urllib.request(url, { timeout: 30 * 1000, }); if (ret.status >= 300) { return { status: ret.status };
0
4
2
166 167 168 169 170 171 172
agentid: this.agentid }; extend(data, to); extend(data, message); urllib.request(url, postJSON(data), wrapper(callback)); };
147
0
1
GitHub: grinfans/Niffler
173 174 175 176 177 178 179 180 181 182
method: 'receive_tx', params: [slate, null, null], } res = await axios.post(url, payload) //console.log('payload', JSON.stringify(payload)) //res = await urllib.request(url, { // method: 'post', // contentType: "application/json", // dataType: 'json', // timeout: '25s',
29
82
10
15 16 17 18 19 20 21 22 23 24
exports.request = async function (url, options = {}) { return new Promise((resolve, reject) => { const headers = { 'X-Auth-Token': process.env.YUE_TOKEN }; urllib.request(url, { headers, timeout: 30000, ...options }, function (err, data, res) { if (err) { reject(err) } else { resolve(data)
2
5
3
GitHub: node-modules/autod
153 154 155 156 157 158 159 160 161 162
// npm don't support range now if (semver.validRange(tag)) { url = `${this.options.registry}/${name}`; isAllVersions = true; } const res = yield urllib.request(url, { headers: { 'user-agent': USER_AGENT, // npm will response less data accept: 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*',
18
205
0
77 78 79 80 81 82 83 84 85 86
dataType: 'json', data: data }; var url = PREFIX + 'singlesend?t=ajax-response&lang=zh_CN'; urllib.request(url, options, function (err, body, res) { if (err) { return callback(err); } if (body.ret !== '0') {
27
39
0
GitHub: balac2015/balac.js2
105 106 107 108 109 110 111 112 113 114
type: type, data: args, agent: this.agent }; var that = this; urllib.request(that.REST_URL, options, function(err, buffer) { var data; if (buffer) { buffer = that._wrapJSON(buffer.toString()); try {
2
0
2
GitHub: iedon/iedon-net-api
20 21 22 23 24 25 26 27 28 29 30
}; const ANTI_REPLAY_ALLOW_SECONDS_RANGE = 600; const DEFAULT_REG_INTERVAL_SECONDS = 30; const DEFAULT_CENTER_SERVER_URL = 'http://api.contoso.com'; const defaultHttpRequestFunc = async (url, options) => await urllib.request(url, options); const defaultLogFunc = (level, log) => { switch (level) { case 'warn': return console.warn(log); case 'error': return console.error(log);
1
2
1
32 33 34 35 36 37 38 39 40
data.stream = form; } else { data.headers['Content-Length'] = 0; }; var req = urllib.request(url, data, callback); return req; }
1
0
0
73 74 75 76 77 78 79 80 81 82
var openid = data.openid var unionid = data.unionid var persistent_code = data.persistent_code if (!openid || !persistent_code) return callback(new Error('getPersistentCode failed')) urllib.request(self._snsTokenURL + '?access_token=' + self.access_token, { headers: { 'Content-Type': 'application/json' }, method: 'POST',
1
0
0
+ 2 other calls in file
GitHub: FoxerLee/Miku
46 47 48 49 50 51 52 53 54 55
data.stream = form; } else { data.headers['Content-Length'] = 0; }; var req = urllib.request(uri, data, function(err, result, res) { var rerr = null; if (err || Math.floor(res.statusCode/100) !== 2) { rerr = {code: res&&res.statusCode||-1, error: err||result.error||''}; }
0
2
0
urllib.request is the most popular function in urllib (367 examples)