1 | import * as AWS from 'aws-sdk';
|
2 | import {IResponse, response} from './tools';
|
3 |
|
4 | AWS.config.update({region: 'us-east-1'});
|
5 |
|
6 |
|
7 |
|
8 | export class Http {
|
9 |
|
10 | private request:any;
|
11 |
|
12 | constructor() {
|
13 | this.request = require("request");
|
14 | }
|
15 |
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | public async post(body: {postData: any}, params: { url: string, headers: any }): Promise<IResponse> {
|
23 | try {
|
24 |
|
25 | let post_data = body.postData;
|
26 |
|
27 | let tsevoresponse = '';
|
28 | const respRequestHTTP = await new Promise<IResponse>((res, rej) => {
|
29 | this.request.post({
|
30 | "headers": params.headers,
|
31 | "url": params.url,
|
32 | "body": JSON.stringify(post_data)
|
33 | }, async (error, resp, pres) => {
|
34 | if (error) {
|
35 | console.log(900, error);
|
36 | rej(response(false, error));
|
37 | }
|
38 | tsevoresponse = await JSON.parse(pres);
|
39 | res(response(true, null, tsevoresponse));
|
40 | })
|
41 | });
|
42 | return respRequestHTTP;
|
43 | } catch (error) {
|
44 | return response(false, error);
|
45 | }
|
46 | }
|
47 |
|
48 | } |
\ | No newline at end of file |