调用该对象的requestInStream()方法,传入http请求的url地址和可选参数,发起网络请求。调用该对象的on(“dataReceive”)方法,订阅响应事件。参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/http-request-0000001821000269\#ZH-CN\_TOPIC\_0000001821000269\_\_requestinstream接口开发步骤// 用于订阅HTTP响应头事件httpRequest.on('headersReceive', (header: Object) => { console.info('header: ' + JSON.stringify(header)); });Response header样例: {“cache-control”:“no-cache”,“connection”:“keep-alive”,“content-encoding”:“gzip”,“content-security-policy”:“frame-ancestors ‘self’ https://*.gitee.com”,“content-type”:“application/json; charset=utf-8”,“date”:“Thu, 28 Mar 2024 01:08:54 GMT”,“expires”:“Sun, 1 Jan 2000 01:00:00 GMT”,“pragma”:“must-revalidate, no-cache, private”,“server”:“ADAS/1.0.201”,“transfer-encoding”:“chunked”,“vary”:“Origin”,“x-content-type-options”:“nosniff”,“x-frame-options”:“SAMEORIGIN”,“x-request-id”:“1e86941cdf6b350e72278cb434b299e2”,“x-runtime”:“0.147106”,“x-ua-compatible”:“chrome=1”,“x-xss-protection”:“1; mode=block”,“set-cookie”:[“user_locale=zh-CN; domain=.gitee.com; path=/; expires=Mon, 28 Mar 2044 01:08:54 -0000”,“oschina_new_user=false; path=/; expires=Mon, 28 Mar 2044 01:08:54 -0000”,“gitee-session-n=VHJUOEhWZ09NelQrZlNoR0ZabHAxWTBLTFZGL05NVG1TQiswRm9neHB2cGp6TElXRGxhTGt4T2krQ1ZmdHRERzEwaEV0VzdPVzNmWkNtRjljVmYrS2c9PS0tL1AxVFBmV1VhMXB4UWV5NE5DemUrdz09–fb0babdf8363b541e705b57e34b03dd12703cb89; domain=.gitee.com; path=/; HttpOnly”,“BEC=1f1759df3ccd099821dcf0da6feb0357;Path=/;Max-Age=126000”]}
调用该对象的requestInStream()方法,传入http请求的url地址和可选参数,发起网络请求。
调用该对象的on(“dataReceive”)方法,订阅响应事件。
参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/http-request-0000001821000269\#ZH-CN\_TOPIC\_0000001821000269\_\_requestinstream
接口开发步骤
// 用于订阅HTTP响应头事件