diff --git a/src/common/utils/request.ts b/src/common/utils/request.ts index cfb22131..bdc2bee6 100644 --- a/src/common/utils/request.ts +++ b/src/common/utils/request.ts @@ -30,16 +30,16 @@ export class RequestUtil { } // 请求和回复都是JSON data传原始内容 自动编码json - static async HttpGetJson(url: string, method: string = 'GET', data?: any, headers: Record = {}) { + static async HttpGetJson(url: string, method: string = 'GET', data?: any, headers: Record = {}): Promise { + let option = new URL(url); const protocol = url.startsWith('https://') ? https : http; const options = { - hostname: url.replace(/^(https?:\/\/)?(.*?)(\/.*)?$/, '$2'), - port: url.startsWith('https://') ? 443 : 80, - path: url.replace(/^(https?:\/\/[^\/]+)?(.*?)(\/.*)?$/, '$3'), + hostname: option.hostname, + port: option.port, + path: option.href, method, headers, }; - return new Promise((resolve, reject) => { const req = protocol.request(options, (res: any) => { let responseBody = ''; @@ -64,11 +64,9 @@ export class RequestUtil { req.on('error', (error: any) => { reject(error); }); - if (method === 'POST' || method === 'PUT' || method === 'PATCH') { req.write(JSON.stringify(data)); } - req.end(); }); } diff --git a/src/common/utils/umami.ts b/src/common/utils/umami.ts index 991f4535..a3c10172 100644 --- a/src/common/utils/umami.ts +++ b/src/common/utils/umami.ts @@ -22,8 +22,8 @@ export async function postLoginStatus() { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0' }); resolve(true); - } catch { - reject('umami post failed') + } catch (e: any) { + reject(e); } }); }