@cc-component/cc-core 1.8.8 → 1.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -68,6 +68,18 @@ export class HttpManager {
|
|
|
68
68
|
timeout: number = 10000;
|
|
69
69
|
/**内部使用 */
|
|
70
70
|
param: any;
|
|
71
|
+
|
|
72
|
+
/** 自定义请求头信息 */
|
|
73
|
+
public headers: Map<string, string> = new Map<string, string>();
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 添加自定义请求头信息
|
|
77
|
+
* @param name 信息名
|
|
78
|
+
* @param value 信息值
|
|
79
|
+
*/
|
|
80
|
+
addHeader(name: string, value: string) {
|
|
81
|
+
this.headers.set(name, value);
|
|
82
|
+
}
|
|
71
83
|
/**
|
|
72
84
|
* GET请求获取文本格式数据
|
|
73
85
|
* @param name 协议名
|
|
@@ -75,9 +87,8 @@ export class HttpManager {
|
|
|
75
87
|
* @returns HTTP请求返回值
|
|
76
88
|
*/
|
|
77
89
|
getText(name: string, params: BodyInit | null = null): Promise<HttpReturn<any>> {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return this.request(name, params, HttpMethod.GET, HttpResponseType.Text, headers);
|
|
90
|
+
this.headers.set(HeaderName, HeaderValueText);
|
|
91
|
+
return this.request(name, params, HttpMethod.GET, HttpResponseType.Text, this.headers);
|
|
81
92
|
}
|
|
82
93
|
|
|
83
94
|
/**
|
|
@@ -87,9 +98,8 @@ export class HttpManager {
|
|
|
87
98
|
* @returns HTTP请求返回值
|
|
88
99
|
*/
|
|
89
100
|
getJson(name: string, params: BodyInit | null = null): Promise<HttpReturn<any>> {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return this.request(name, params, HttpMethod.GET, HttpResponseType.Json, headers);
|
|
101
|
+
this.headers.set(HeaderName, HeaderValueJson);
|
|
102
|
+
return this.request(name, params, HttpMethod.GET, HttpResponseType.Json, this.headers);
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
/**
|
|
@@ -99,9 +109,8 @@ export class HttpManager {
|
|
|
99
109
|
* @returns HTTP请求返回值
|
|
100
110
|
*/
|
|
101
111
|
postJson(name: string, params: BodyInit | null = null, ext?: IExtData): Promise<HttpReturn<any>> {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return this.request(name, params, HttpMethod.POST, HttpResponseType.Json, headers, ext);
|
|
112
|
+
this.headers.set(HeaderName, HeaderValueJson);
|
|
113
|
+
return this.request(name, params, HttpMethod.POST, HttpResponseType.Json, this.headers, ext);
|
|
105
114
|
}
|
|
106
115
|
|
|
107
116
|
/**
|
|
@@ -123,10 +132,8 @@ export class HttpManager {
|
|
|
123
132
|
pb = null;
|
|
124
133
|
}
|
|
125
134
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
let r = await this.request<T>(cmd.toString(), pb, HttpMethod.POST, HttpResponseType.ArrayBuffer, headers);
|
|
135
|
+
this.headers.set(HeaderName, HeaderValuePb);
|
|
136
|
+
let r = await this.request<T>(cmd.toString(), pb, HttpMethod.POST, HttpResponseType.ArrayBuffer, this.headers);
|
|
130
137
|
if (r.isSucc) {
|
|
131
138
|
let u8a = new Uint8Array(r.res as any);
|
|
132
139
|
let decode = pc[res].decode(u8a);
|