Request 路径的bug

This commit is contained in:
禾几海
2020-07-01 00:08:13 +08:00
parent 718a7516af
commit c265ff68fc
2 changed files with 7 additions and 5 deletions

View File

@@ -23,6 +23,7 @@ export class HttpService {
}
Service<T>(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<HttpResponse<Response<T>>>;
switch (request.method) {
@@ -73,7 +74,7 @@ export class HttpService {
}
private get<T>(request: RequestObj) {
return this.httpClient.get<T>(request.path,
return this.httpClient.get<T>(request.url,
{
headers: request.header,
withCredentials: true,
@@ -82,7 +83,7 @@ export class HttpService {
}
private post<T>(request: RequestObj) {
return this.httpClient.post<T>(request.path, request.data,
return this.httpClient.post<T>(request.url, request.data,
{
headers: request.header,
withCredentials: true,
@@ -91,7 +92,7 @@ export class HttpService {
}
private put<T>(request: RequestObj) {
return this.httpClient.put<T>(request.path, request.data,
return this.httpClient.put<T>(request.url, request.data,
{
headers: request.header,
withCredentials: true,
@@ -100,7 +101,7 @@ export class HttpService {
}
private delete<T>(request: RequestObj) {
return this.httpClient.delete<T>(request.path,
return this.httpClient.delete<T>(request.url,
{
headers: request.header,
withCredentials: true,

View File

@@ -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';