From 4e32aa12dd0892482b3057df66ff1e19635d3e7e Mon Sep 17 00:00:00 2001 From: wangyingjun01 Date: Thu, 26 Sep 2024 18:16:02 +0800 Subject: [PATCH] =?UTF-8?q?httpclient=E7=BB=84=E4=BB=B6=E4=B8=AD=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E5=9B=BD=E9=99=85=E5=8C=96=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyingjun01 --- .../main/ets/model/TLSSocketListenerImpl.ets | 16 +- entry/src/main/ets/pages/CustomRequest.ets | 4 +- .../pages/bidirectionalCustomCertificate.ets | 2 +- .../src/main/ets/pages/certificate_pinner.ets | 2 +- entry/src/main/ets/pages/core.ets | 4 +- entry/src/main/ets/pages/dns.ets | 4 +- .../main/resources/base/element/string.json | 30 +- .../main/resources/en_US/element/string.json | 532 ------------------ .../main/resources/zh_CN/element/string.json | 28 + .../src/main/ets/pages/Axios.ets | 70 +-- .../src/main/ets/pages/adapterTest.ets | 123 +++- .../main/resources/base/element/string.json | 64 +++ .../main/resources/en_US/element/string.json | 16 - .../main/resources/zh_CN/element/string.json | 64 +++ 14 files changed, 348 insertions(+), 611 deletions(-) delete mode 100644 entry/src/main/resources/en_US/element/string.json delete mode 100644 entryAxiosForHttpclient/src/main/resources/en_US/element/string.json diff --git a/entry/src/main/ets/model/TLSSocketListenerImpl.ets b/entry/src/main/ets/model/TLSSocketListenerImpl.ets index 4d69c1a..ddef184 100644 --- a/entry/src/main/ets/model/TLSSocketListenerImpl.ets +++ b/entry/src/main/ets/model/TLSSocketListenerImpl.ets @@ -40,6 +40,10 @@ export class TLSSocketListenerImpl extends TLSSocketListener { } } + getResourceString(res: Resource) { + return getContext().resourceManager.getStringSync(res.id) + } + onMessage(err: BusinessError, data: OnMsgData): void { if (!!!err) { let bufferContent = buffer.from(data.message) @@ -73,9 +77,9 @@ export class TLSSocketListenerImpl extends TLSSocketListener { onSend(err: BusinessError, data: string) { if (!!!err) { - this.content += '\ntlsSoket:onSend:data:发送成功' + this.content += '\ntlsSoket:onSend:data:' + this.getResourceString($r('app.string.Sent_successfully')) promptAction.showToast({ - message: "消息发送成功", + message: $r('app.string.Message_successfully'), duration: 1000 }) } else { @@ -105,8 +109,8 @@ export class TLSSocketListenerImpl extends TLSSocketListener { }) if (err['errorNumber'] = -1 || JSON.stringify(err).includes('951')) { this.content = ""; - this.content += '\ntlsSoket:onError:err:连接不上服务器,请确认服务器是否可用,确认客户端是否联网' - this.errorMsg = { code: -1, errorMsg: "连接不上服务器,请确认服务器是否可用,确认客户端是否联网" }; + this.content += '\ntlsSoket:onError:err:' + this.getResourceString($r('app.string.Unable_internet')) + this.errorMsg = { code: -1, errorMsg: this.getResourceString($r('app.string.Unable_internet') )}; } } } @@ -114,7 +118,7 @@ export class TLSSocketListenerImpl extends TLSSocketListener { onVerify(verifyName: string, error: string, data: string) { let onVerifyData: CertVerifyResult = { code: -1, verificationResult: "Certificate verification failed" } if (!!!error) { - onVerifyData = { code: 0, name: verifyName, verificationData: data, verificationResult: "校验通过" }; + onVerifyData = { code: 0, name: verifyName, verificationData: data, verificationResult: this.getResourceString($r('app.string.Verification_passed')) }; } else { onVerifyData = { code: -1, verificationResult: error }; } @@ -123,7 +127,7 @@ export class TLSSocketListenerImpl extends TLSSocketListener { setExtraOptions(err: BusinessError, data: string) { if (!!!err) { - this.content += '\ntlsSoket:setExtraOptions:data:设置成功' + this.content += '\ntlsSoket:setExtraOptions:data:' + this.getResourceString($r('app.string.Setting_successful')) } else { this.content += '\ntlsSoket:setExtraOptions:err:' + JSON.stringify(err) } diff --git a/entry/src/main/ets/pages/CustomRequest.ets b/entry/src/main/ets/pages/CustomRequest.ets index 1ffa092..70aa787 100644 --- a/entry/src/main/ets/pages/CustomRequest.ets +++ b/entry/src/main/ets/pages/CustomRequest.ets @@ -124,7 +124,7 @@ struct CustomRequest { .fontSize("18fp") .margin(10) - Button('异步自定义请求') + Button($r('app.string.Asynchronous_request')) .width('80%') .height('80px') .fontSize(18) @@ -156,7 +156,7 @@ struct CustomRequest { this.property_two_queue = this.getResourceString($r('app.string.Attribute_values')) + "\r\n" + result.result.city; console.log('Custom Request Object Properties == ' + result.result.city) }, (error: BusinessError) => { - this.result_queue = "请求结果:\r\n" + JSON.stringify(error); + this.result_queue = this.getResourceString($r('app.string.Request_result')) +"\r\n" + JSON.stringify(error); hilog.info(0x0001, "Custom Request error == ", JSON.stringify(error)); }) }) diff --git a/entry/src/main/ets/pages/bidirectionalCustomCertificate.ets b/entry/src/main/ets/pages/bidirectionalCustomCertificate.ets index 1345513..2724644 100644 --- a/entry/src/main/ets/pages/bidirectionalCustomCertificate.ets +++ b/entry/src/main/ets/pages/bidirectionalCustomCertificate.ets @@ -40,7 +40,7 @@ const TAG: string = "customCertificate_Bidirectional"; struct bidirectionalCustomCertificate { @State url: string = "https://1.94.37.200:8443/user/getUserByUuid?userUuid=1"; @State unSecureUrl: string = "http://106.15.92.248:9090/login.jsp"; - @State result: string = "响应结果" + @State result: string = this.getResourceString($r('app.string.Response_results')); ca = "noPassword/ca.crt"; clientKey = "noPassword/clientKey.crt"; clientCert = "noPassword/clientCer.crt"; diff --git a/entry/src/main/ets/pages/certificate_pinner.ets b/entry/src/main/ets/pages/certificate_pinner.ets index 8c87daa..9e2aff1 100644 --- a/entry/src/main/ets/pages/certificate_pinner.ets +++ b/entry/src/main/ets/pages/certificate_pinner.ets @@ -32,7 +32,7 @@ import { CertificatePinner } from '@ohos/httpclient/src/main/ets/CertificatePinn @Component struct certificatePinner { @State url: string | undefined = 'https://1.94.37.200:8080/user/getUserByUuid?userUuid=1'; - @State result: string | undefined = '响应结果'; + @State result: string | undefined = this.getResourceString($r('app.string.Response_results')); @State hostname: string | undefined = '1.94.37.200'; @State successPin: string | undefined = 'sha256/WAFcHG6pAINrztx343nlM3jYzLOdfoDS9pPgMvD2XHk='; @State failPin: string | undefined = 'sha1/f58c753eff28a6c'; diff --git a/entry/src/main/ets/pages/core.ets b/entry/src/main/ets/pages/core.ets index d17c449..ffbb2fe 100644 --- a/entry/src/main/ets/pages/core.ets +++ b/entry/src/main/ets/pages/core.ets @@ -271,7 +271,7 @@ struct Core { .padding(10) Flex({ direction: FlexDirection.Column }) { - Button('https-POST-表单提交') + Button($r('app.string.Https_Submission')) .width('80%') .height('100%') .fontSize(18) @@ -318,7 +318,7 @@ struct Core { .padding(10) Flex({ direction: FlexDirection.Column }) { - Button('http-POST-表单提交') + Button($r('app.string.Https_Submission')) .width('80%') .height('100%') .fontSize(18) diff --git a/entry/src/main/ets/pages/dns.ets b/entry/src/main/ets/pages/dns.ets index d55b2ec..138d9c7 100644 --- a/entry/src/main/ets/pages/dns.ets +++ b/entry/src/main/ets/pages/dns.ets @@ -37,7 +37,7 @@ struct dns { @State jdUrl: string = 'https://www.jd.com'; @State baiduUrl: string = 'https://www.baidu.com'; @State urlTest: string = 'http://139.9.217.131:8001'; - @State result: string = '响应结果'; + @State result: string = this.getResourceString($r('app.string.Response_results')); scroller: Scroller = new Scroller(); hereResourceManager: resmgr.ResourceManager = getContext().resourceManager; TEST_CA = 'wanandroidRoot.crt'; @@ -56,7 +56,7 @@ struct dns { target: '', type: NavigationType.Back }) { - Text('BACK') + Text($r('app.string.BACK')) .fontSize(10) .border({ width: 1 diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 211771b..c9adb67 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -527,6 +527,34 @@ { "name": "Request_responsiveData", "value": "Request to configure responsiveData" + }, + { + "name": "Https_Submission", + "value": "Https POST - Form Submission" + }, + { + "name": "Asynchronous_request", + "value": "Asynchronous custom request" + }, + { + "name": "Message_successfully", + "value": "Message sent successfully" + }, + { + "name": "Sent_successfully", + "value": "Sent successfully" + }, + { + "name": "Unable_internet", + "value": "Unable to connect to the server, please confirm if the server is available and if the client is connected to the internet" + }, + { + "name": "Verification_passed", + "value": "Verification passed" + }, + { + "name": "Setting_successful", + "value": "Setting successful" } ] -} \ No newline at end of file +} diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json deleted file mode 100644 index 211771b..0000000 --- a/entry/src/main/resources/en_US/element/string.json +++ /dev/null @@ -1,532 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "label" - }, - { - "name": "Request_status", - "value": "Request status: " - }, - { - "name": "Request_Header", - "value": "Request Header: " - }, - { - "name": "Request_result", - "value": "Request result: " - }, - { - "name": "identity_authentication", - "value": "identity authentication" - }, - { - "name": "BACK", - "value": "BACK" - }, - { - "name": "Http_Custom_Encryption", - "value": "Http: Custom Encryption" - }, - { - "name": "Custom_authentication", - "value": "Custom encrypted identity authentication" - }, - { - "name": "Custom_encryption", - "value": "Custom encryption:" - }, - { - "name": "Accessing", - "value": "Accessing.." - }, - { - "name": "Request_address", - "value": "Request address:" - }, - { - "name": "Request_Requesting", - "value": "Request status: Requesting in progress" - }, - { - "name": "Request_401", - "value": "Request status: 401, identity authentication required" - }, - { - "name": "Request_password1", - "value": "Request status: Authentication username: jesse, password: password1" - }, - { - "name": "Authentication_certificate", - "value": "Authentication certificate: Authorization:" - }, - { - "name": "Request_again", - "value": "Request status: Identity authentication started, requesting again" - }, - { - "name": "Request_follows", - "value": "Request status: Identity authentication completed, request successful, content as follows:" - }, - { - "name": "Please_URL", - "value": "Please enter URL" - }, - { - "name": "GET_request", - "value": "GET request 1: Verify successful request" - }, - { - "name": "Custom_certificate", - "value": "Custom certificate return success, result: " - }, - { - "name": "Custom_failed", - "value": "Custom certificate return failed, result: " - }, - { - "name": "GET_request_2", - "value": "GET request 2: Verification failed, intercept request" - }, - { - "name": "Load_certificate", - "value": "Load certificate" - }, - { - "name": "Enter_server_IP", - "value": "Enter server IP address" - }, - { - "name": "Enter_port", - "value": "Enter server port" - }, - { - "name": "Connect_to_server", - "value": "Connect to server" - }, - { - "name": "Enter_sent", - "value": "Enter the content to be sent" - }, - { - "name": "send_data", - "value": "send data" - }, - { - "name": "Certificate_verification_result", - "value": "Certificate verification result: " - }, - { - "name": "IP_result", - "value": "IP and port binding result:" - }, - { - "name": "Connection_result", - "value": "Connection to server result:" - }, - { - "name": "Received_result", - "value": "Received server message result:" - }, - { - "name": "link", - "value": "link" - }, - { - "name": "Please_hostname", - "value": "Please enter hostname" - }, - { - "name": "Please_fingerprint", - "value": "Please enter successful fingerprint" - }, - { - "name": "Please_failed_fingerprint", - "value": "Please enter the failed fingerprint" - }, - { - "name": "Initiate_verification", - "value": "Initiate request - verification passed" - }, - { - "name": "Response_result_success", - "value": "Response result: success" - }, - { - "name": "Response_failed", - "value": "Response result failed" - }, - { - "name": "Initiate_failed", - "value": "Initiate request - verification failed" - }, - { - "name": "Upload_Progress", - "value": "Upload Progress:" - }, - { - "name": "Encoding_successful", - "value": "Encoding successful" - }, - { - "name": "Encoding_data", - "value": "Encoding data:" - }, - { - "name": "Decoding_successful", - "value": "Decoding successful" - }, - { - "name": "Decoded_data", - "value": "Decoded data:" - }, - { - "name": "Encoding_path", - "value": "Encoding file path:" - }, - { - "name": "Original_path", - "value": "Original encoding file path:" - }, - { - "name": "Decoding_path", - "value": "Decoding path:" - }, - { - "name": "File_size", - "value": "File size:" - }, - { - "name": "Decoding_result", - "value": "Decoding result:" - }, - { - "name": "Uploading", - "value": "Uploading.." - }, - { - "name": "Current_upload", - "value": "Current upload size:" - }, - { - "name": "Upload_total", - "value": "Upload total file size:" - }, - { - "name": "Upload_file_path", - "value": "Upload file path:" - }, - { - "name": "Upload_completed", - "value": "Upload completed" - }, - { - "name": "Upload_result", - "value": "Upload result:" - }, - { - "name": "Downloading", - "value": "Downloading.." - }, - { - "name": "Download_size", - "value": "Download file size:" - }, - { - "name": "Total_files", - "value": "Total size of downloaded files:" - }, - { - "name": "Download_path", - "value": "Download file path:" - }, - { - "name": "Download_successful", - "value": "Download successful" - }, - { - "name": "Download_content", - "value": "Download file content:" - }, - { - "name": "Request_failed", - "value": "Request status: Request failed" - }, - { - "name": "Visiting", - "value": "Visiting.." - }, - { - "name": "Send_original", - "value": "Send original text" - }, - { - "name": "Send_encoded_text", - "value": "Send encoded text" - }, - { - "name": "Return_status", - "value": "Return status:" - }, - { - "name": "Return_result", - "value": "Return result:" - }, - { - "name": "Return_header", - "value": "Return header:" - }, - { - "name": "Attribute_values", - "value": "Attribute values of the object:" - }, - { - "name": "What_object", - "value": "What you get is a custom weather object" - }, - { - "name": "Synchronize_requests", - "value": "Synchronize custom requests" - }, - { - "name": "Request_Connectivity", - "value": "Request DNS Method 1: Normal Connectivity" - }, - { - "name": "Response_result_1", - "value": "Response result 1" - }, - { - "name": "Request_Pass", - "value": "Request DNS Method 2: Custom DNS Pass in" - }, - { - "name": "Response_result_2", - "value": "Response result 2" - }, - { - "name": "Request_Baidu", - "value": "Request DNS method 3: redirect to Baidu" - }, - { - "name": "Response_result_3", - "value": "Response result 3" - }, - { - "name": "Request_method", - "value": "Request DNS method 4:2303501" - }, - { - "name": "Response_result_4", - "value": "Response result 4" - }, - { - "name": "Response_result_5", - "value": "Response result 5" - }, - { - "name": "Request_DNS_Method", - "value": "Request DNS Method 5:2100002" - }, - { - "name": "Interceptor_method", - "value": "Interceptor method" - }, - { - "name": "Response_results", - "value": "Response results" - }, - { - "name": "clear", - "value": "clear" - }, - { - "name": "Request_method_4", - "value": "Request DNS method 4:2303501" - }, - { - "name": "URL_address", - "value": "URL address" - }, - { - "name": "Customize_get", - "value": "Customize EventListener+get" - }, - { - "name": "Customize_post", - "value": "Customize EventListener+post" - }, - { - "name": "empty", - "value": "empty" - }, - { - "name": "Response_status", - "value": "Response status:" - }, - { - "name": "Response_data", - "value": "Response data:" - }, - { - "name": "Status_code", - "value": "Status code:" - }, - { - "name": "Custom_Certificate", - "value": "Custom Certificate - Bidirectional Certificate" - }, - { - "name": "Custom_Unidirectional", - "value": "Custom Certificate _ Unidirectional Certificate" - }, - { - "name": "Certificate_verification", - "value": "Certificate verification" - }, - { - "name": "Request_queue", - "value": "Request queue+priority" - }, - { - "name": "Certificate_Lock", - "value": "Certificate Lock" - }, - { - "name": "Set_proxy", - "value": "Set up proxy" - }, - { - "name": "IP_Selection", - "value": "IP Optimal Selection" - }, - { - "name": "The_maximum_64", - "value": "The maximum number of request queues is 64" - }, - { - "name": "The_maximum_5", - "value": "The maximum number of Host requests is 5" - }, - { - "name": "Details_Running_queue", - "value": "Details: Running queue" - }, - { - "name": "For_queue", - "value": "For example, waiting queue" - }, - { - "name": "example", - "value": "example" - }, - { - "name": "Please_request_queues", - "value": "Please enter the new maximum number of request queues" - }, - { - "name": "Confirm_modifications", - "value": "Confirm modifications" - }, - { - "name": "The_queues_is", - "value": "The maximum number of request queues is:" - }, - { - "name": "Please_Host_requests", - "value": "Please enter the new maximum number of same Host requests" - }, - { - "name": "The_Host_requests", - "value": "The maximum number of Host requests is:" - }, - { - "name": "Initiate_request", - "value": "Initiate a request" - }, - { - "name": "Proxy_server_IP", - "value": "Proxy server IP" - }, - { - "name": "Enter_IP_address", - "value": "Enter server IP address" - }, - { - "name": "Proxy_server_port", - "value": "Proxy server port" - }, - { - "name": "Enter_server_port", - "value": "Enter server port" - }, - { - "name": "Request_URL", - "value": "Request URL" - }, - { - "name": "Request_network", - "value": "Request network" - }, - { - "name": "Return_value", - "value": "Return value:" - }, - { - "name": "Input_interface", - "value": "Input cache interface" - }, - { - "name": "Query_result_source", - "value": "Query result source:" - }, - { - "name": "Return_code", - "value": "Return code:" - }, - { - "name": "network", - "value": "network" - }, - { - "name": "Modified_successfully", - "value": "Modified successfully" - }, - { - "name": "cache", - "value": "cache" - }, - { - "name": "Response_header", - "value": "Response header:" - }, - { - "name": "Server", - "value": "Server--" - }, - { - "name": "Client", - "value": "Client side--" - }, - { - "name": "Please_enter_WebSocket", - "value": "Please enter the URL of WebSocket type" - }, - { - "name": "Upload_successful", - "value": "Upload_successful" - }, - { - "name": "Request_responsiveData", - "value": "Request to configure responsiveData" - } - ] -} \ No newline at end of file diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index a695ac8..1bc4747 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -527,6 +527,34 @@ { "name": "Request_responsiveData", "value": "请求配置responseData" + }, + { + "name": "Https_Submission", + "value": "https-POST-表单提交" + }, + { + "name": "Asynchronous_request", + "value": "异步自定义请求" + }, + { + "name": "Message_successfully", + "value": "消息发送成功" + }, + { + "name": "Sent_successfully", + "value": "发送成功" + }, + { + "name": "Unable_internet", + "value": "连接不上服务器,请确认服务器是否可用,确认客户端是否联网" + }, + { + "name": "Verification_passed", + "value": "校验通过" + }, + { + "name": "Setting_successful", + "value": "设置成功" } ] } \ No newline at end of file diff --git a/entryAxiosForHttpclient/src/main/ets/pages/Axios.ets b/entryAxiosForHttpclient/src/main/ets/pages/Axios.ets index 6515816..7d12206 100644 --- a/entryAxiosForHttpclient/src/main/ets/pages/Axios.ets +++ b/entryAxiosForHttpclient/src/main/ets/pages/Axios.ets @@ -53,9 +53,12 @@ struct Axios { clientCertNoPassword: string = DEMO_CONFIG.clientCertNoPassword; clientCertHasPassword: string = DEMO_CONFIG.clientCertHasPassword; proxyUrl: string = DEMO_CONFIG.proxyUrl; - psw:string = DEMO_CONFIG.psw; - host: string = DEMO_CONFIG.host; + psw: string = DEMO_CONFIG.psw; + host: string = DEMO_CONFIG.host; + getResourceString(res: Resource) { + return getContext().resourceManager.getStringSync(res.id) + } build() { Scroll(this.scroller) { @@ -68,7 +71,7 @@ struct Axios { .margin({ top: 20, bottom: 25 }) //请求按钮 - Flex({direction: FlexDirection.Row, alignItems: ItemAlign.Start ,wrap:FlexWrap.Wrap}){ + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Start, wrap: FlexWrap.Wrap }) { Button('Get') .width(100) .margin({ @@ -85,56 +88,56 @@ struct Axios { this.post() }) - Button('拦截器').width(100).margin({ + Button($r('app.string.Interceptor')).width(100).margin({ bottom: 10, right: 10 }).onClick((e) => { this.interceptors() }) - Button('默认设置').width(100).margin({ + Button($r('app.string.default_setting')).width(100).margin({ bottom: 10, right: 10 }).onClick((e) => { this.defaultSetting() }) - Button('下载').width(100).margin({ + Button($r('app.string.Download')).width(100).margin({ bottom: 10, right: 10 }).onClick((e) => { this.download() }) - Button('上传').width(100).margin({ + Button($r('app.string.Upload')).width(100).margin({ bottom: 10, right: 10 }).onClick((e) => { this.upload() }) - Button('双向校验(无密码)').width(100).margin({ + Button($r('app.string.Bidirectional_verification')).width(100).margin({ bottom: 10, right: 10 }).onClick((e) => { this.settingClientCert() }) - Button('双向校验(有密码)').width(100).margin({ + Button($r('app.string.Bidirectional_password')).width(100).margin({ bottom: 10, right: 10 }).onClick((e) => { this.settingClientCert_psw() }) - Button('设置响应类型').width(100).margin({ + Button($r('app.string.Set_response')).width(100).margin({ bottom: 10, right: 10 }).onClick((e) => { this.settingResponseType() }) - Button('设置代理').width(100).margin({ + Button($r('app.string.Set_proxy')).width(100).margin({ bottom: 10, right: 10 }).onClick((e) => { @@ -143,11 +146,11 @@ struct Axios { } //请求地址 - Column(){ - Text('请求地址') + Column() { + Text($r('app.string.Request_address')) .fontSize(18) .fontWeight(FontWeight.Bold) - .margin({bottom: 10}) + .margin({ bottom: 10 }) Text(this.showUrl) .width('100%') .height(50) @@ -158,27 +161,27 @@ struct Axios { .borderWidth(1) .borderColor('#E6E7E8') } - .margin({top: 10, bottom: 20}) + .margin({ top: 10, bottom: 20 }) .alignItems(HorizontalAlign.Start) //请求结果 - Column(){ - Text('请求结果') + Column() { + Text($r('app.string.Request_result')) .fontSize(18) .fontWeight(FontWeight.Bold) - .margin({bottom: 10}) + .margin({ bottom: 10 }) .textAlign(TextAlign.Start) //进度条 - if (this.showUrl === this.uploadUrl){ - Text('上传进度') + if (this.showUrl === this.uploadUrl) { + Text($r('app.string.Upload_Progress')) Progress({ value: this.uploadProgress, type: ProgressType.Linear }) .color('#009BE8').width('100%') .margin({ top: 8, right: 10 }) .style({ strokeWidth: 10 }) } - if (this.showUrl === this.downloadUrl){ - Text('下载进度') + if (this.showUrl === this.downloadUrl) { + Text($r('app.string.Download_progress')) Progress({ value: this.downloadProgress, type: ProgressType.Linear }) .color('#009BE8').width('100%') .margin({ top: 8, right: 10 }) @@ -206,16 +209,17 @@ struct Axios { .borderWidth(1) .borderColor('#E6E7E8') } - .margin({top: 10, bottom: 20}) + .margin({ top: 10, bottom: 20 }) .alignItems(HorizontalAlign.Start) - Button('清空输入框内容').width(120).onClick((e) => { + + Button($r('app.string.Clear_content')).width(120).onClick((e) => { this.clear() }) } } .scrollable(ScrollDirection.Vertical) // 滚动方向纵向 .scrollBar(BarState.On) // 滚动条常驻显示 - .margin({left: 10, right: 10}) + .margin({ left: 10, right: 10 }) } // get请求 @@ -265,7 +269,7 @@ struct Axios { const myInterceptor = axios.interceptors.response.use((response: AxiosResponse) => { // 对响应数据做点什么 console.info(TAG, JSON.stringify(response.data)) - response.data = '在拦截器中,内容被更改了' + response.data = this.getResourceString($r('app.string.In_altered')) return response; }, (error: AxiosError) => { // 对响应错误做点什么 @@ -331,7 +335,8 @@ struct Axios { context: getContext(this), filePath: filePath, onDownloadProgress: (progressEvent: AxiosProgressEvent): void => { - this.downloadProgress = progressEvent && progressEvent.loaded && progressEvent.total ? Math.ceil(progressEvent.loaded / progressEvent.total * 100) : 0; + this.downloadProgress = progressEvent && progressEvent.loaded && progressEvent.total ? + Math.ceil(progressEvent.loaded / progressEvent.total * 100) : 0; } }).then((res: AxiosResponse) => { this.status = res ? res.status : ''; @@ -350,12 +355,12 @@ struct Axios { let context: Context = getContext(this); let ca: Uint8Array = context.resourceManager.getRawFileContentSync("oneWayAuth/ca.pem"); let cacheDir: string = context.cacheDir; - let buffer:ArrayBuffer = new ArrayBuffer(1024); + let buffer: ArrayBuffer = new ArrayBuffer(1024); try { writeFile(cacheDir, 'ca.pem', ca.buffer); // 读取 buffer = readFile(cacheDir + '/ca.pem'); - }catch (err){ + } catch (err) { console.error(TAG, JSON.stringify(err)) } @@ -368,7 +373,8 @@ struct Axios { context: getContext(this), onUploadProgress: (progressEvent: AxiosProgressEvent): void => { console.info(TAG, JSON.stringify(progressEvent)) - this.uploadProgress = progressEvent && progressEvent.loaded && progressEvent.total ? Math.ceil(progressEvent.loaded / progressEvent.total * 100) : 0; + this.uploadProgress = progressEvent && progressEvent.loaded && progressEvent.total ? + Math.ceil(progressEvent.loaded / progressEvent.total * 100) : 0; }, }).then((res: AxiosResponse) => { this.status = res ? res.status : ''; @@ -428,7 +434,7 @@ struct Axios { }).then((res: AxiosResponse) => { this.status = res ? res.status : ''; this.message = res ? JSON.stringify(res.data) : ''; - console.info(TAG, ) + console.info(TAG,) }).catch((err: AxiosError) => { this.status = ''; this.message = err.message; @@ -504,7 +510,7 @@ struct Axios { }).then((res: AxiosResponse) => { this.status = res ? res.status : ''; if (res.data instanceof ArrayBuffer) { - this.message = res ? 'responseType设置成功' : ''; + this.message = res ? this.getResourceString($r('app.string.ResponseType_successfully')) : ''; } }).catch((err: AxiosError) => { this.status = ''; diff --git a/entryAxiosForHttpclient/src/main/ets/pages/adapterTest.ets b/entryAxiosForHttpclient/src/main/ets/pages/adapterTest.ets index e2a0984..fa82b23 100644 --- a/entryAxiosForHttpclient/src/main/ets/pages/adapterTest.ets +++ b/entryAxiosForHttpclient/src/main/ets/pages/adapterTest.ets @@ -56,7 +56,7 @@ struct adapterTest { target: "", type: NavigationType.Back }) { - Text('BACK') + Text($r('app.string.BACK')) .fontSize(10) .border({ width: 1 @@ -66,6 +66,7 @@ struct adapterTest { .borderColor(0x317aff) } } + Text('axios') .fontSize(28) .fontWeight(700) @@ -81,14 +82,26 @@ struct adapterTest { .borderStyle(BorderStyle.Solid) .borderWidth(1) .borderColor('#E6E7E8') - .padding({ top: 5, bottom: 5, left: 10, right: 10 }) + .padding({ + top: 5, + bottom: 5, + left: 10, + right: 10 + }) .margin({ right: 10 }) Button('sslCertificateManager').width(120).onClick((e) => { this.sslCertificateManager(); }).visibility(this.showButton) } .width('100%') - }.padding({ left: 20, right: 20, bottom: 20, top: 0 }).width('100%') + } + .padding({ + left: 20, + right: 20, + bottom: 20, + top: 0 + }) + .width('100%') Row() { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) { @@ -100,7 +113,12 @@ struct adapterTest { .borderStyle(BorderStyle.Solid) .borderWidth(1) .borderColor('#E6E7E8') - .padding({ top: 5, bottom: 5, left: 10, right: 10 }) + .padding({ + top: 5, + bottom: 5, + left: 10, + right: 10 + }) .margin({ right: 10 }) Button('priority').width(120).onClick((e) => { this.showButton = Visibility.Hidden @@ -108,7 +126,14 @@ struct adapterTest { }) } .width('100%') - }.padding({ left: 20, right: 20, bottom: 20, top: 0 }).width('100%') + } + .padding({ + left: 20, + right: 20, + bottom: 20, + top: 0 + }) + .width('100%') Row() { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) { @@ -120,14 +145,26 @@ struct adapterTest { .borderStyle(BorderStyle.Solid) .borderWidth(1) .borderColor('#E6E7E8') - .padding({ top: 5, bottom: 5, left: 10, right: 10 }) + .padding({ + top: 5, + bottom: 5, + left: 10, + right: 10 + }) .margin({ right: 10 }) Button('DNS').width(120).onClick((e) => { this.dns(); }).visibility(this.showButton) } .width('100%') - }.padding({ left: 20, right: 20, bottom: 20, top: 0 }).width('100%') + } + .padding({ + left: 20, + right: 20, + bottom: 20, + top: 0 + }) + .width('100%') Row() { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) { @@ -139,14 +176,26 @@ struct adapterTest { .borderStyle(BorderStyle.Solid) .borderWidth(1) .borderColor('#E6E7E8') - .padding({ top: 5, bottom: 5, left: 10, right: 10 }) + .padding({ + top: 5, + bottom: 5, + left: 10, + right: 10 + }) .margin({ right: 10 }) Button('EventListener').width(120).onClick((e) => { this.eventListener(); }).visibility(this.showButton) } .width('100%') - }.padding({ left: 20, right: 20, bottom: 20, top: 0 }).width('100%') + } + .padding({ + left: 20, + right: 20, + bottom: 20, + top: 0 + }) + .width('100%') Row() { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) { @@ -158,14 +207,26 @@ struct adapterTest { .borderStyle(BorderStyle.Solid) .borderWidth(1) .borderColor('#E6E7E8') - .padding({ top: 5, bottom: 5, left: 10, right: 10 }) + .padding({ + top: 5, + bottom: 5, + left: 10, + right: 10 + }) .margin({ right: 10 }) Button('setProxy').width(120).onClick((e) => { this.setProxy(); }).visibility(this.showButton) } .width('100%') - }.padding({ left: 20, right: 20, bottom: 20, top: 0 }).width('100%') + } + .padding({ + left: 20, + right: 20, + bottom: 20, + top: 0 + }) + .width('100%') Row() { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) { @@ -177,14 +238,26 @@ struct adapterTest { .borderStyle(BorderStyle.Solid) .borderWidth(1) .borderColor('#E6E7E8') - .padding({ top: 5, bottom: 5, left: 10, right: 10 }) + .padding({ + top: 5, + bottom: 5, + left: 10, + right: 10 + }) .margin({ right: 10 }) Button('CertificatePinner').width(120).onClick((e) => { this.certificatePinner(); }).visibility(this.showButton) } .width('100%') - }.padding({ left: 20, right: 20, bottom: 20, top: 0 }).width('100%') + } + .padding({ + left: 20, + right: 20, + bottom: 20, + top: 0 + }) + .width('100%') Row() { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) { @@ -196,14 +269,26 @@ struct adapterTest { .borderStyle(BorderStyle.Solid) .borderWidth(1) .borderColor('#E6E7E8') - .padding({ top: 5, bottom: 5, left: 10, right: 10 }) + .padding({ + top: 5, + bottom: 5, + left: 10, + right: 10 + }) .margin({ right: 10 }) Button('cache').width(120).onClick((e) => { this.cache(); }).visibility(this.showButton) } .width('100%') - }.padding({ left: 20, right: 20, bottom: 20, top: 0 }).width('100%') + } + .padding({ + left: 20, + right: 20, + bottom: 20, + top: 0 + }) + .width('100%') Row() { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Start }) { @@ -231,7 +316,13 @@ struct adapterTest { this.clear(); }).visibility(this.showButton) } - }.padding({ left: 20, right: 20, bottom: 20, top: 0 }) + } + .padding({ + left: 20, + right: 20, + bottom: 20, + top: 0 + }) } } diff --git a/entryAxiosForHttpclient/src/main/resources/base/element/string.json b/entryAxiosForHttpclient/src/main/resources/base/element/string.json index 2b3b929..8d76791 100644 --- a/entryAxiosForHttpclient/src/main/resources/base/element/string.json +++ b/entryAxiosForHttpclient/src/main/resources/base/element/string.json @@ -11,6 +11,70 @@ { "name": "EntryAxiosForHttpclientAbility_label", "value": "label" + }, + { + "name": "BACK", + "value": "BACK" + }, + { + "name": "Interceptor", + "value": "Interceptor" + }, + { + "name": "default_setting", + "value": "default setting" + }, + { + "name": "Download", + "value": "Download" + }, + { + "name": "Upload", + "value": "Upload" + }, + { + "name": "Bidirectional_verification", + "value": "Bidirectional verification (no password)" + }, + { + "name": "Bidirectional_password", + "value": "Bidirectional verification (with password)" + }, + { + "name": "Set_response", + "value": "Set response type" + }, + { + "name": "Set_proxy", + "value": "Set up proxy" + }, + { + "name": "Request_address", + "value": "Request address" + }, + { + "name": "Request_result", + "value": "Request result" + }, + { + "name": "Upload_Progress", + "value": "Upload Progress" + }, + { + "name": "Download_progress", + "value": "Download Progress" + }, + { + "name": "Clear_content", + "value": "Clear the input box content" + }, + { + "name": "In_altered", + "value": "In the interceptor, the content has been altered" + }, + { + "name": "ResponseType_successfully", + "value": "ResponseType set successfully" } ] } \ No newline at end of file diff --git a/entryAxiosForHttpclient/src/main/resources/en_US/element/string.json b/entryAxiosForHttpclient/src/main/resources/en_US/element/string.json deleted file mode 100644 index 2b3b929..0000000 --- a/entryAxiosForHttpclient/src/main/resources/en_US/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAxiosForHttpclientAbility_desc", - "value": "description" - }, - { - "name": "EntryAxiosForHttpclientAbility_label", - "value": "label" - } - ] -} \ No newline at end of file diff --git a/entryAxiosForHttpclient/src/main/resources/zh_CN/element/string.json b/entryAxiosForHttpclient/src/main/resources/zh_CN/element/string.json index e65f133..b91e110 100644 --- a/entryAxiosForHttpclient/src/main/resources/zh_CN/element/string.json +++ b/entryAxiosForHttpclient/src/main/resources/zh_CN/element/string.json @@ -11,6 +11,70 @@ { "name": "EntryAxiosForHttpclientAbility_label", "value": "label" + }, + { + "name": "BACK", + "value": "返回" + }, + { + "name": "Interceptor", + "value": "拦截器" + }, + { + "name": "default_setting", + "value": "默认设置" + }, + { + "name": "Download", + "value": "下载" + }, + { + "name": "Upload", + "value": "上传" + }, + { + "name": "Bidirectional_verification", + "value": "双向校验(无密码)" + }, + { + "name": "Bidirectional_password", + "value": "双向校验(有密码)" + }, + { + "name": "Set_response", + "value": "设置响应类型" + }, + { + "name": "Set_proxy", + "value": "设置代理" + }, + { + "name": "Request_address", + "value": "请求地址" + }, + { + "name": "Request_result", + "value": "请求结果" + }, + { + "name": "Upload_Progress", + "value": "上传进度" + }, + { + "name": "Download_progress", + "value": "下载进度" + }, + { + "name": "Clear_content", + "value": "清空输入框内容" + }, + { + "name": "In_altered", + "value": "在拦截器中,内容被更改了" + }, + { + "name": "ResponseType_successfully", + "value": "responseType设置成功" } ] } \ No newline at end of file -- Gitee