From c265ff68fcc73b89fd3f4b09e42753f3a0b1a8e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BE=E5=87=A0=E6=B5=B7?= Date: Wed, 1 Jul 2020 00:08:13 +0800 Subject: [PATCH] =?UTF-8?q?Request=20=E8=B7=AF=E5=BE=84=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/http/http.service.ts | 11 ++++++----- src/app/class/HttpReqAndResp.ts | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/app/api/http/http.service.ts b/src/app/api/http/http.service.ts index a9e4e04..7d3171c 100644 --- a/src/app/api/http/http.service.ts +++ b/src/app/api/http/http.service.ts @@ -23,6 +23,7 @@ export class HttpService { } Service(request: RequestObj) { + request.url = null; // 设置默认值 request.contentType = request.contentType == null ? 'application/x-www-form-urlencoded' : request.contentType; request.header = { @@ -32,7 +33,7 @@ export class HttpService { if (token != null) { request.header.Authorization = token; } - request.path = this.checkUrl(request); + request.url = this.checkUrl(request); let observable: Observable>>; switch (request.method) { @@ -73,7 +74,7 @@ export class HttpService { } private get(request: RequestObj) { - return this.httpClient.get(request.path, + return this.httpClient.get(request.url, { headers: request.header, withCredentials: true, @@ -82,7 +83,7 @@ export class HttpService { } private post(request: RequestObj) { - return this.httpClient.post(request.path, request.data, + return this.httpClient.post(request.url, request.data, { headers: request.header, withCredentials: true, @@ -91,7 +92,7 @@ export class HttpService { } private put(request: RequestObj) { - return this.httpClient.put(request.path, request.data, + return this.httpClient.put(request.url, request.data, { headers: request.header, withCredentials: true, @@ -100,7 +101,7 @@ export class HttpService { } private delete(request: RequestObj) { - return this.httpClient.delete(request.path, + return this.httpClient.delete(request.url, { headers: request.header, withCredentials: true, diff --git a/src/app/class/HttpReqAndResp.ts b/src/app/class/HttpReqAndResp.ts index 33ba9f1..4371115 100644 --- a/src/app/class/HttpReqAndResp.ts +++ b/src/app/class/HttpReqAndResp.ts @@ -2,6 +2,7 @@ import {HttpHeaders} from '@angular/common/http'; export class RequestObj { path: string; + url?: string; // 仅在httpService里面进行使用 method: 'GET' | 'POST' | 'PUT' | 'DELETE'; data?: {}; contentType?: 'application/json' | 'application/x-www-form-urlencoded';