|
1 | 1 | const assign = require('object-assign')
|
2 | 2 | const qs = require('querystring')
|
3 | 3 | const dotQs = require('dot-qs')
|
4 |
| -const https = require('https') |
| 4 | +const request = require('../lib/request/index') |
5 | 5 | const crypto = require('crypto')
|
6 | 6 | const cos = require('../lib/cos/cos')
|
7 | 7 |
|
@@ -65,22 +65,39 @@ class TencentCloudClient {
|
65 | 65 |
|
66 | 66 | async doCloudApiRequest(data) {
|
67 | 67 | const httpBody = await this.cloudApiGenerateQueryString(data)
|
68 |
| - const options = { |
69 |
| - hostname: this.service.host, |
70 |
| - path: this.service.path + '?' + httpBody |
71 |
| - } |
72 |
| - return new Promise(function(resolve, reject) { |
73 |
| - const req = https.get(options, function(res) { |
74 |
| - res.setEncoding('utf8') |
75 |
| - res.on('data', function(chunk) { |
76 |
| - resolve(JSON.parse(chunk)) |
77 |
| - }) |
78 |
| - }) |
79 |
| - req.on('error', function(e) { |
80 |
| - reject(e.message) |
81 |
| - }) |
82 |
| - // req.write(httpBody) |
83 |
| - req.end() |
| 68 | + |
| 69 | + // const options = { |
| 70 | + // hostname: this.service.host, |
| 71 | + // path: this.service.path + '?' + httpBody |
| 72 | + // } |
| 73 | + // return new Promise(function(resolve, reject) { |
| 74 | + // const req = https.get(options, function(res) { |
| 75 | + // res.setEncoding('utf8') |
| 76 | + // res.on('data', function(chunk) { |
| 77 | + // resolve(JSON.parse(chunk)) |
| 78 | + // }) |
| 79 | + // }) |
| 80 | + // req.on('error', function(e) { |
| 81 | + // reject(e.message) |
| 82 | + // }) |
| 83 | + // // req.write(httpBody) |
| 84 | + // req.end() |
| 85 | + // }) |
| 86 | + |
| 87 | + const url = `https://${this.service.host}${this.service.path}?${httpBody}` |
| 88 | + return new Promise(function(resolve, rejecte) { |
| 89 | + request( |
| 90 | + { |
| 91 | + url: url, |
| 92 | + method: 'GET' |
| 93 | + }, |
| 94 | + function(error, response, body) { |
| 95 | + if (!error && response.statusCode == 200) { |
| 96 | + resolve(JSON.parse(body)) |
| 97 | + } |
| 98 | + rejecte(error) |
| 99 | + } |
| 100 | + ) |
84 | 101 | })
|
85 | 102 | }
|
86 | 103 | }
|
|
0 commit comments