外贸企业网站制作公司,怎么建立本地网站,紫金优化网站制作,网页传奇游戏单职业场景介绍
发送一个HTTP请求#xff0c;也可以设置请求头和请求体等参数#xff0c;并返回来自服务器的HTTP响应。使用Promise异步回调。常用于获取资源#xff0c;支持流处理和通过拦截器来处理请求和响应。
接口说明
接口名描述fetch(request: Request): Promise发送一个…场景介绍
发送一个HTTP请求也可以设置请求头和请求体等参数并返回来自服务器的HTTP响应。使用Promise异步回调。常用于获取资源支持流处理和通过拦截器来处理请求和响应。
接口说明
接口名描述fetch(request: Request): Promise发送一个HTTP请求并返回来自服务器的HTTP响应。使用Promise异步回调。
使用示例
导入模块。
import { rcp } from kit.RemoteCommunicationKit;
import { BusinessError } from kit.BasicServicesKit;创建Request对象。https://www.example.com请根据实际情况替换为想要请求的URL地址。
const kHttpServerAddress https://www.example.com/fetch;
const request new rcp.Request(kHttpServerAddress, GET);创建会话。 const session rcp.createSession();发起请求并处理返回结果。
session.fetch(request).then((rep: rcp.Response) {console.info(Response succeeded: ${rep});
}).catch((err: BusinessError) {console.error(Response err: Code is ${err.code}, message is ${JSON.stringify(err)});
});