Skip to content

Commit a24a0c5

Browse files
authored
Merge pull request #7 from Ekipogh/bugfix/port
Add port to request options in post function
2 parents 613d9cf + 106636e commit a24a0c5

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

dist/utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ async function post({ url, body, header, json }) {
4949
header['Content-Length'] = Buffer.byteLength(data);
5050
const options = {
5151
hostname: url_.hostname,
52+
port: url_.port || (url_.protocol === "http:" ? 80 : 443),
5253
path: url_.pathname + (url_.search || ''),
5354
method: 'POST',
5455
headers: header
@@ -91,7 +92,7 @@ async function post({ url, body, header, json }) {
9192
}
9293
}
9394
catch (error) {
94-
reject(new Error('Failed to parse :' + responseBody));
95+
reject(new Error('Failed to parse : \'' + responseBody + '\'' + ' with error: ' + error.message));
9596
}
9697
});
9798
});

src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export async function post({url, body, header, json}: any): Promise<string> {
4343
header['Content-Length'] = Buffer.byteLength(data)
4444
const options = {
4545
hostname: url_.hostname, // 确保去掉协议部分
46+
port: url_.port || (url_.protocol === "http:" ? 80 : 443),
4647
path: url_.pathname + (url_.search || ''),
4748
method: 'POST',
4849
headers: header
@@ -85,7 +86,7 @@ export async function post({url, body, header, json}: any): Promise<string> {
8586
resolve(responseBody);
8687
}
8788
} catch (error) {
88-
reject(new Error('Failed to parse :' + responseBody));
89+
reject(new Error('Failed to parse : \'' + responseBody + '\'' + ' with error: ' + error.message));
8990
}
9091
});
9192
});

0 commit comments

Comments
 (0)