|
@@ -1,6 +1,6 @@
|
|
|
import { ArrayList, HashMap } from '@kit.ArkTS';
|
|
|
import http from '@ohos.net.http';
|
|
|
-import { LogHelper } from '../../../../Index';
|
|
|
+import { LogHelper, ToolsHelper } from '../../../../Index';
|
|
|
import { SZYXLocalStorageHelper } from '../utils/SZYXLocalStorageHelper';
|
|
|
import { SZYXLocalStorageKeys } from '../utils/SZYXLocalStorageKeys';
|
|
|
import { HttpHelperX, HttpParamsForm, HttpParamsGet, HttpParamsPost, HttpParamsUpload } from './HttpHelperX';
|
|
@@ -340,31 +340,24 @@ export class HttpHelper {
|
|
|
if (showLog) {
|
|
|
LogHelper.debug(`postJson:${apiNo}\n`, JSON.stringify(params))
|
|
|
}
|
|
|
- // let data = HttpHelperX.getContent(params.data)
|
|
|
-
|
|
|
-
|
|
|
- // const formData: http.MultiFormData[] = params.data as http.MultiFormData[]
|
|
|
+ httpRequest.on("dataSendProgress", (data: http.DataSendProgressInfo) => {
|
|
|
+ ToolsHelper.log(`${apiNo}:\n${JSON.stringify(data)}`)
|
|
|
+ });
|
|
|
httpRequest.request(HttpHelperX.getUrl(params.url, params.query), {
|
|
|
method: http.RequestMethod.POST,
|
|
|
connectTimeout: 20000,
|
|
|
readTimeout: 20000,
|
|
|
header: header,
|
|
|
- extraData: params.data,
|
|
|
usingCache: false,
|
|
|
multiFormDataList: params.data,
|
|
|
})
|
|
|
.then((data: http.HttpResponse) => {
|
|
|
+
|
|
|
if (showLog) {
|
|
|
LogHelper.debug(`${apiNo}:\n ${data.result as string}`)
|
|
|
LogHelper.print(data)
|
|
|
}
|
|
|
|
|
|
- if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
- this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
- this.httpHandlerList.length)
|
|
|
- }
|
|
|
if (data.responseCode === 200) {
|
|
|
resolve((typeof data.result === 'string' ? JSON.parse(data.result) : data.result) as T)
|
|
|
} else {
|
|
@@ -374,13 +367,8 @@ export class HttpHelper {
|
|
|
reject(err)
|
|
|
}
|
|
|
}).catch((err: Error) => {
|
|
|
+
|
|
|
LogHelper.error(JSON.stringify({ err: err, url: params.url, }))
|
|
|
- if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
- this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
- SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
- this.httpHandlerList.length)
|
|
|
- }
|
|
|
if (err.message === 'Failed writing received data to disk/application') {
|
|
|
const error: Error = new Error()
|
|
|
error.name = 'cancel'
|
|
@@ -389,6 +377,14 @@ export class HttpHelper {
|
|
|
} else {
|
|
|
reject(err)
|
|
|
}
|
|
|
+ }).finally(() => {
|
|
|
+ httpRequest.off("dataSendProgress");
|
|
|
+ if (this.httpHandlerList.hasKey(apiNo ?? params.url)) {
|
|
|
+ this.httpHandlerList.remove(apiNo ?? params.url)
|
|
|
+ SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerList, this.httpHandlerList)
|
|
|
+ SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.HttpHandlerListLength,
|
|
|
+ this.httpHandlerList.length)
|
|
|
+ }
|
|
|
});
|
|
|
});
|
|
|
|