httpRequestGet('http://test.xxx').then((result: ResponseResult)=>{let data = result.data as ResponseTokenconsole.log("msg="+ result.msg)console.log("token="+ data.access_token)})
import{ http }from'@kit.NetworkKit';import ResponseResult from'./ResponseResult';/*** Initiate an HTTP GET request to the specified URL.*/exportfunctionhttpRequestGet(url:string){returnhttpRequest(url, http.RequestMethod.GET);}/*** Initiate an HTTP POST request to the specified URL.*/exportfunctionhttpRequestPost(url:string, newsData:string){returnhttpRequest(url, http.RequestMethod.POST, newsData);}/*** Initiates an HTTP request to a given URL.** @param url URL for initiating an HTTP request* @param method Request method.* @param extraData Additional data of the request.* @returns Returns {@link ResponseResult}.*/functionhttpRequest(url:string, method: http.RequestMethod, params?:string):Promise<ResponseResult>{let httpRequest = http.createHttp();let responseResult = httpRequest.request(url,{method: method,header:{'Content-Type':'application/json'},extraData: params});let serverData =newResponseResult();// Processes the data and returns.return responseResult.then((value: http.HttpResponse)=>{if(value.responseCode ===200){// Obtains the returned data.let result =`${value.result}`;let resultJson: ResponseResult =JSON.parse(result);if(resultJson.code ==='000000'){serverData.data = resultJson.data;}serverData.code = resultJson.code;serverData.msg = resultJson.msg;}else{serverData.msg =`Network request failed, please try later!&${value.responseCode}`;}return serverData;}).catch(()=>{serverData.msg ='Network request failed, please try later!';return serverData;});}
ResponseResult为服务端返回的基本结构
exportdefaultclassResponseResult{/*** Code returned by the network request: success, fail.*/code:string;/*** Message returned by the network request.*/msg:string| Resource;/*** Data returned by the network request.*/data:string| Object | ArrayBuffer;constructor(){this.code ='';this.msg ='';this.data ='';}}
我一直在尝试从各种角度撰写关于Amazon Web Services(AWS)的信息和魅力。由于我喜欢技术历史,这次我总结了AWS服务发布的历史年表。
虽然AWS官方也通过“Whats New”发布了官方公告,但我一直希望能有一篇文章将公告日期、GA日期&…
可以使用Math.Round()方法进行四舍五入取整数的操作。
以下是使用Math.Round()方法的实现方法: 将浮点数直接作为参数传递给Math.Round()方法,并指定要保留的小数位数。此方法将返回最接近的整数值。 double number 3.89;
int roundedNumber (int)Mat…