鸿蒙6.1 @ohos.net.http坑:HttpDataType常量STRING不是STRING_TYPE+HttpRequest interface不能new
鸿蒙 6.1 API 23 开发坑系列篇 7ohos.net.http HTTP 请求坑——HttpDataType 常量是 STRING 不是 STRING_TYPE HttpRequest 是 interface 不能 new http.createHttp() 造实例根因本文是「鸿蒙 6.1 API 23 开发坑系列」第 7 篇非 UI 系第 1 篇。本篇讲ohos.net.httpnamespaceAPI 6鸿蒙 6.1 API 23 基座——HTTP 请求HttpRequesthttp.createHttp()HttpDataType/RequestMethodenum on/off监听 request/requestInStream方法。鸿蒙坑根因①HttpDataTypeenum 常量是STRING不是STRING_TYPE跟字面量string对应enum 值是数字0②HttpRequest是 interface 不能newnew http.HttpRequest()编译错Cannot use new with an interface必须用http.createHttp()工厂函数造实例③on(headersReceive)/off(headersReceive, callback)监听响应头不是addEventListener/removeEventListener④HttpRequestOptions.header是Recordstring, string不是Headers对象不能new Headers()⑤RequestMethodenum 常量GET/POST/PUT/DELETE不是字符串GET。一、开篇鸿蒙 http 不是 fetch是「http.createHttp() 工厂造 HttpRequest 实例 on/off 监听」你写前端时HTTP 请求用fetchPromise 链Headers 对象addEventListener 监听// React fetchPromise 链Headers 对象addEventListener 监听 const headers new Headers() // ✅ 前端 Headers 对象可以 new headers.append(Content-Type, application/json) const res await fetch(https://api.example.com/data, { method: GET, // ✅ 前端 method 是字符串 GET headers }) const data await res.json() // ✅ 前端 fetch 返回 Promise.json() 取 body你写鸿蒙 ArkTS 时HTTP 请求用http.createHttp()工厂造HttpRequest实例HttpRequest是 interface 不能newon/off监听request方法带回调// ArkTS http.createHttp()工厂造 HttpRequest 实例on/off 监听request 方法带回调 import http from ohos.net.http // ✅ default importhttp 是 namespace const httpRequest: http.HttpRequest http.createHttp() // ✅ 工厂函数造实例不是 new http.HttpRequest() const options: http.HttpRequestOptions { method: http.RequestMethod.GET, // ✅ RequestMethod enum 常量 GET不是字符串 GET header: { Content-Type: application/json }, // ✅ header 是 Recordstring, string 不是 Headers 对象 expectDataType: http.HttpDataType.STRING // ✅ HttpDataType 常量 STRING不是 STRING_TYPE } httpRequest.request(https://api.example.com/data, options, (err, data) { // ✅ request 带回调不是 Promise if (!err) { console.info(response: data.result) // ✅ data.result 是响应体STRING 类型返回 string } }) // 鸿蒙坑根因HttpDataType STRING 不是 STRING_TYPEHttpRequest interface 不能 new 用 http.createHttp()fetch vs 鸿蒙 http 的区别前端把 HTTP 请求当浏览器 APIfetch(url, init)返回PromiseResponseHeaders对象可以newmethod是字符串GETaddEventListener监听ArkTS 把 HTTP 请求当 ArkUI 命名空间工厂http.createHttp()造HttpRequest实例HttpRequest是 interface 不能newmethod是RequestMethodenum 常量不是字符串header是Recordstring, string不是Headers对象on/off监听不是addEventListener。根因不是浏览器 API 是 ArkTS 命名空间工厂——鸿蒙HttpRequest是 interface 不能new必须http.createHttp()工厂造实例HttpDataTypeenum 常量是STRING不是STRING_TYPE跟字面量string对应enum 值是数字0。二、根因鸿蒙 ohos.net.http 的五个绑定机制鸿蒙ohos.net.httpnamespaceAPI 6核心导出http.createHttp()工厂函数 HttpRequestinterface HttpDataType/RequestMethodenum HttpRequestOptions/HttpResponse类型。绑定机制来自五重根因。机制 1HttpDataType enum 常量是 STRING 不是 STRING_TYPE——跟字面量“string“对应enum 值是数字 0鸿蒙坑根因HttpDataTypeenum 常量是STRING不是STRING_TYPE跟字面量string对应enum 值是数字0// ❌ 鸿蒙坑HttpDataType 常量是 STRING 不是 STRING_TYPESTRING_TYPE 不存在编译错 import http from ohos.net.http // ❌ STRING_TYPE 常量不存在编译错 has no exported member STRING_TYPE const badType: http.HttpDataType http.HttpDataType.STRING_TYPE // ❌ STRING_TYPE 不存在 // ✅ 正确用法HttpDataType.STRING 常量跟字面量string对应enum 值是数字 0 const dataType: http.HttpDataType http.HttpDataType.STRING // ✅ 常量真名 STRING 不是 STRING_TYPE console.info(STRING${dataType}) // ✅ STRING0enum 值是数字 0 // ✅ HttpDataType enum 三个常量STRING0 / ARRAY_BUFFER1 / OBJECT2 const strType: http.HttpDataType http.HttpDataType.STRING // ✅ STRING0字符串 const binType: http.HttpDataType http.HttpDataType.ARRAY_BUFFER // ✅ ARRAY_BUFFER1ArrayBuffer const objType: http.HttpDataType http.HttpDataType.OBJECT // ✅ OBJECT2Object // 鸿蒙坑根因HttpDataType 常量是 STRING 不是 STRING_TYPE跟字面量string对应enum 值是数字 0HttpDataType 常量名坑根因鸿蒙HttpDataTypeenum 的三个常量是STRING0字符串类型、ARRAY_BUFFER1ArrayBuffer 二进制类型、OBJECT2Object 对象类型。鸿蒙坑前端 fetch 的responseType是字符串string/arraybuffer/json鸿蒙HttpDataType是 enum 常量不是字符串且常量真名是STRING不是STRING_TYPE——STRING_TYPE是其他库如 ohos.buffer的命名风格鸿蒙ohos.net.http的HttpDataType用STRING跟字面量string对应去掉_TYPE后缀enum 值是数字0不是字符串。ReactresponseType: string是字符串鸿蒙expectDataType: http.HttpDataType.STRING是 enum 常量。机制 2HttpRequest 是 interface 不能 new——用 http.createHttp() 工厂函数造实例鸿蒙坑根因HttpRequest是 interface 不能new必须用http.createHttp()工厂函数造实例// ❌ 鸿蒙坑HttpRequest 是 interface 不能 newnew http.HttpRequest() 编译错 import http from ohos.net.http // ❌ HttpRequest 是 interface 不能 new编译错Cannot use new with an interface const badReq: http.HttpRequest new http.HttpRequest() // ❌ interface 不能 new // ✅ 正确用法http.createHttp() 工厂函数造 HttpRequest 实例 const httpRequest: http.HttpRequest http.createHttp() // ✅ 工厂函数造实例不是 new // 鸿蒙坑根因HttpRequest 是 interface 不能 new必须 http.createHttp() 工厂函数造实例HttpRequest interface 坑根因鸿蒙ohos.net.http.d.ts的HttpRequest声明是export interface HttpRequest { ... }interface 不是 classinterface 没有构造函数不能new。鸿蒙坑new http.HttpRequest()触发Cannot use new with an interface编译错ArkTS 严格模式 interface 不能实例化——必须用http.createHttp()工厂函数造实例工厂函数内部走 native 造实例跟new不同。前端fetch是全局函数不需要造实例XMLHttpRequest是 class 可以new XMLHttpRequest()鸿蒙HttpRequest是 interface 不能new——必须http.createHttp()工厂。机制 3on(‘headersReceive’)/off 监听响应头——不是 addEventListener/removeEventListener鸿蒙坑根因on(headersReceive)/off(headersReceive, callback)监听响应头不是addEventListener/removeEventListener// ❌ 鸿蒙坑on/off 监听不是 addEventListener/removeEventListener import http from ohos.net.http const httpRequest: http.HttpRequest http.createHttp() // ❌ addEventListener/removeEventListener 不存在HttpRequest interface 没有这两个方法 // httpRequest.addEventListener(headersReceive, callback) // ❌ addEventListener 不存在 // httpRequest.removeEventListener(headersReceive, callback) // ❌ removeEventListener 不存在 // ✅ 正确用法on(headersReceive, callback)/off(headersReceive, callback) 监听响应头 const headersCallback (data: Object) { console.info(headersReceive: JSON.stringify(data)) } httpRequest.on(headersReceive, headersCallback) // ✅ on 监听响应头不是 addEventListener httpRequest.off(headersReceive, headersCallback) // ✅ off 取消监听callback 传同一个引用 // 鸿蒙坑根因on/off 监听不是 addEventListener/removeEventListeneroff callback 传同一个引用on/off 监听坑根因鸿蒙HttpRequestinterface 的监听方法是on(type: string, callback: AsyncCallbackObject): void和off(type: string, callback?: AsyncCallbackObject): void跟篇 5uiObserver.on/off同构不是前端的addEventListener/removeEventListener。鸿蒙坑HttpRequestinterface 没有addEventListener/removeEventListener方法编译错Property does not exist——必须用on/off且off的 callback 必须传同一个引用不是匿名函数匿名函数每次创建新引用无法匹配取消不传 callback 则取消该 type 所有监听。前端XMLHttpRequest.addEventListener(load, cb)是 DOM 方法鸿蒙httpRequest.on(headersReceive, cb)是 namespace 风格方法。机制 4HttpRequestOptions.header 是 Recordstring, string 不是 Headers 对象鸿蒙坑根因HttpRequestOptions.header是Recordstring, string不是Headers对象不能new Headers()// ❌ 鸿蒙坑header 是 Recordstring, string 不是 Headers 对象不能 new Headers() import http from ohos.net.http // ❌ Headers 对象不存在ohos.net.http 没有 Headers 类型new Headers() 编译错 const badHeaders new Headers() // ❌ Headers 类型不存在ohos.net.http 没导出 const badOptions: http.HttpRequestOptions { method: http.RequestMethod.GET, header: badHeaders // ❌ header 不是 Headers 对象是 Recordstring, string } // ✅ 正确用法header 是 Recordstring, string对象字面量键值都是 string const options: http.HttpRequestOptions { method: http.RequestMethod.GET, header: { Content-Type: application/json, Authorization: Bearer xxx } // ✅ Recordstring, string } // 鸿蒙坑根因header 是 Recordstring, string 不是 Headers 对象不能用 new Headers()header 类型坑根因鸿蒙HttpRequestOptions.header的类型是Recordstring, string对象字面量键和值都是 string不是前端的Headers对象。鸿蒙坑前端fetch的headers是Headers对象new Headers()可以造headers.append(key, value)添加鸿蒙ohos.net.http没有Headers类型header直接是Recordstring, string对象字面量{ Content-Type: application/json }——new Headers()编译错Cannot find name Headers鸿蒙没导出Headers类型。前端Headers对象有append/delete/get方法鸿蒙Recordstring, string是普通对象没方法直接赋值。机制 5RequestMethod enum 常量 GET/POST/PUT/DELETE——不是字符串“GET“鸿蒙坑根因RequestMethodenum 常量GET/POST/PUT/DELETE/HEAD/OPTIONS/CONNECT不是字符串GET// ❌ 鸿蒙坑method 是 RequestMethod enum 常量不是字符串GET import http from ohos.net.http // ❌ method 传字符串GET编译错RequestMethod enum 不是 string const badOptions: http.HttpRequestOptions { method: GET, // ❌ method 类型是 RequestMethod enum 不是 string header: { Content-Type: application/json } } // ✅ 正确用法method 传 RequestMethod enum 常量 GET/POST/PUT/DELETE const options: http.HttpRequestOptions { method: http.RequestMethod.GET, // ✅ RequestMethod enum 常量 GET不是字符串GET header: { Content-Type: application/json } } // ✅ RequestMethod enum 常量GET0 / POST1 / PUT2 / DELETE3 / HEAD4 / OPTIONS5 / CONNECT6 const postOpt: http.HttpRequestOptions { method: http.RequestMethod.POST } // ✅ POST1 const putOpt: http.HttpRequestOptions { method: http.RequestMethod.PUT } // ✅ PUT2 const delOpt: http.HttpRequestOptions { method: http.RequestMethod.DELETE } // ✅ DELETE3 // 鸿蒙坑根因method 是 RequestMethod enum 常量不是字符串GETenum 值是数字 0~6RequestMethod enum 坑根因鸿蒙RequestMethodenum 的常量是GET0/POST1/PUT2/DELETE3/HEAD4/OPTIONS5/CONNECT6跟前端 fetch 的method: GET字符串不同。鸿蒙坑前端fetch的method是字符串GET/POST鸿蒙HttpRequestOptions.method的类型是RequestMethodenum 不是 string——传字符串GET触发Type string is not assignable to type RequestMethod编译错必须传http.RequestMethod.GETenum 常量enum 值是数字0不是字符串。Reactmethod: GET是字符串鸿蒙method: http.RequestMethod.GET是 enum 常量。三、真机配图鸿蒙 ohos.net.http HTTP 请求坑——HttpDataType STRING HttpRequest interface http.createHttp()真机配图展示鸿蒙 ohos.net.http HTTP 请求坑初始态鸿蒙 6.1 ohos.net.http HTTP 请求坑标题4 个验证按钮① HttpDataType STRING 常量 / ② HttpRequest interface 不能 new / ③ on/off headersReceive 监听 / ④ requestOptions dataTypeheader请求状态requestStatus 未请求 responseType 未设 HttpDataType 值未读要点说明 7 条HttpDataType STRING 常量态点击「① 验证 HttpDataType STRING 常量」按钮显示「✅ HttpDataType.STRING 常量验证真名 STRING 不是 STRING_TYPE值0」 HttpDataType 值 STRING0——HttpDataType 常量真名 STRING 验证HttpRequest interface 不能 new 态点击「② 验证 HttpRequest interface 不能 new」按钮显示「✅ http.createHttp() 造 HttpRequest 实例验证interface 不能 new用工厂函数」——HttpRequest interface 不能 new http.createHttp() 工厂验证on/off headersReceive 监听态点击「③ 验证 on/off headersReceive 监听」按钮显示「✅ on(“headersReceive”)/off 监听验证on 不是 addEventListeneroff 不是 removeEventListener」——on/off 监听不是 addEventListener/removeEventListener 验证requestOptions dataTypeheader 态点击「④ 验证 requestOptions dataType header」按钮显示「✅ HttpRequestOptions 验证method RequestMethod.GET expectDataType HttpDataType.STRING header Record」——requestOptions enum 常量 header Record 验证四、真解法鸿蒙 ohos.net.http 的四个场景场景 1http.createHttp() 造 HttpRequest request GET 请求——90% 场景首选基础 GET 请求用http.createHttp()造实例 request(url, options, callback)方法// ✅ 场景 1http.createHttp() 造 HttpRequest request GET 请求API 690% 场景首选 import http from ohos.net.http // ✅ default importhttp 是 namespace Entry Component struct Index { State responseData: string (未请求) private httpRequest: http.HttpRequest | null null // ✅ 持引用避免析构 aboutToDisappear() { this.httpRequest?.destroy() // ✅ destroy() 主动销毁避免内存泄漏 this.httpRequest null } sendGetRequest() { // ✅ http.createHttp() 工厂造实例不是 new http.HttpRequest()interface 不能 new this.httpRequest http.createHttp() const options: http.HttpRequestOptions { method: http.RequestMethod.GET, // ✅ RequestMethod enum 常量 GET不是字符串GET header: { Content-Type: application/json }, // ✅ Recordstring, string 不是 Headers 对象 expectDataType: http.HttpDataType.STRING, // ✅ HttpDataType 常量 STRING不是 STRING_TYPE connectTimeout: 60000, readTimeout: 60000 } // ✅ request(url, options, callback) 带回调不是 Promise this.httpRequest.request(https://api.example.com/data, options, (err, data) { if (!err) { // ✅ data.result 是响应体expectDataTypeSTRING 时 data.result 是 string this.responseData data.result as string // ✅ STRING 类型 result 是 string console.info(statusCode: data.responseCode) } else { console.info(error: JSON.stringify(err)) } }) } build() { Column({ space: 8 }) { Text(this.responseData).fontSize(12) } } } // http.createHttp() request GET90% 场景首选HttpDataType STRING RequestMethod enum 常量鸿蒙 ohos.net.http API 真名坑import http from ohos.net.httpdefault importhttp是 namespacehttp.createHttp(): HttpRequest工厂函数造HttpRequest实例不是new http.HttpRequest()——HttpRequest是 interface 不能 newhttp.HttpRequest.request(url: string, options: HttpRequestOptions, callback: AsyncCallbackHttpResponse): void带回调不是 Promisehttp.HttpRequest.destroy(): void主动销毁避免内存泄漏http.HttpDataTypeenum 常量STRING0/ARRAY_BUFFER1/OBJECT2不是STRING_TYPEhttp.RequestMethodenum 常量GET0/POST1/PUT2/DELETE3不是字符串SysCapSystemCapability.Communication.NetStackatomicservice原子化服务权限ohos.permission.INTERNETmodule.json5 里 requestPermission。场景 2on(‘headersReceive’)/off 监听响应头 request POST 带 bodyPOST 请求带 body on(headersReceive)监听响应头// ✅ 场景 2on(headersReceive)/off 监听响应头 request POST 带 bodyAPI 6 import http from ohos.net.http this.httpRequest http.createHttp() // ✅ on(headersReceive, callback) 监听响应头——不是 addEventListener const headersCallback (data: Object) { console.info(响应头: JSON.stringify(data)) } this.httpRequest.on(headersReceive, headersCallback) // ✅ on 监听响应头 const options: http.HttpRequestOptions { method: http.RequestMethod.POST, // ✅ RequestMethod.POST enum 常量 header: { Content-Type: application/json }, extraData: JSON.stringify({ username: admin, password: xxx }), // ✅ extraData 是 POST body expectDataType: http.HttpDataType.STRING } this.httpRequest.request(https://api.example.com/login, options, (err, data) { if (!err) { console.info(response: data.result) } }) // ✅ off(headersReceive, callback) 取消监听——callback 传同一个引用 this.httpRequest.off(headersReceive, headersCallback) // ✅ off 取消监听同引用 // on/off headersReceive 监听 POST extraData bodyon 不是 addEventListeneroff callback 同引用鸿蒙 on/off POST API 真名坑http.HttpRequest.on(type: string, callback: AsyncCallbackObject): void监听type 支持headersReceive响应头/dataReceiveEnd数据接收结束/dataReceiveProgress数据接收进度http.HttpRequest.off(type: string, callback?: AsyncCallbackObject): void取消监听callback 可选不传取消所有http.HttpRequestOptions.extraData: string | Object | ArrayBufferPOST 请求体GET 请求不用鸿蒙坑前端XMLHttpRequest.addEventListener(load, cb)是 DOM 方法鸿蒙httpRequest.on(headersReceive, cb)是 namespace 风格方法前端 POST body 用body字段鸿蒙 POST body 用extraData字段不是body。场景 3requestInStream 流式请求 ARRAY_BUFFER 二进制响应流式请求用requestInStreamARRAY_BUFFER二进制响应类型// ✅ 场景 3requestInStream 流式请求 ARRAY_BUFFER 二进制响应API 6 import http from ohos.net.http this.httpRequest http.createHttp() const options: http.HttpRequestOptions { method: http.RequestMethod.GET, header: { Content-Type: application/json }, expectDataType: http.HttpDataType.ARRAY_BUFFER // ✅ ARRAY_BUFFER1不是 STRING } // ✅ requestInStream 流式请求回调多次触发每次返回一段数据 this.httpRequest.requestInStream(https://api.example.com/stream, options, (err, data) { if (!err) { // ✅ expectDataTypeARRAY_BUFFER 时 data.result 是 ArrayBuffer const buffer: ArrayBuffer data.result as ArrayBuffer // ✅ ARRAY_BUFFER 类型 result 是 ArrayBuffer console.info(收到流数据: buffer.byteLength bytes) } }) // requestInStream 流式 ARRAY_BUFFERexpectDataType 用 ARRAY_BUFFER 常量不是 STRING鸿蒙 requestInStream ARRAY_BUFFER API 真名坑http.HttpRequest.requestInStream(url: string, options: HttpRequestOptions, callback: AsyncCallbackHttpResponse): void流式请求回调多次触发每次返回一段数据不是request一次性返回expectDataType: http.HttpDataType.ARRAY_BUFFER时data.result是ArrayBuffer二进制数据不是 string鸿蒙坑前端fetch流式用ReadableStreamresponse.body.getReader()鸿蒙requestInStream用回调多次触发前端二进制用response.arrayBuffer()鸿蒙expectDataType: ARRAY_BUFFERdata.result as ArrayBuffer。场景 4destroy() 主动销毁 usingCache 缓存 priority 优先级请求完destroy()主动销毁 usingCache缓存控制 priority优先级// ✅ 场景 4destroy() 主动销毁 usingCache 缓存 priority 优先级API 6 import http from ohos.net.http this.httpRequest http.createHttp() const options: http.HttpRequestOptions { method: http.RequestMethod.GET, header: { Content-Type: application/json }, expectDataType: http.HttpDataType.STRING, usingCache: true, // ✅ usingCachetrue 使用缓存不是 cache: force-cache 字符串 priority: 0, // ✅ priority 数字优先级0 最高不是 high/low 字符串 connectTimeout: 60000, // ✅ 连接超时毫秒 readTimeout: 60000 // ✅ 读取超时毫秒 } this.httpRequest.request(https://api.example.com/data, options, (err, data) { if (!err) { console.info(response: data.result) } // ✅ 请求完后调 destroy() 主动销毁避免内存泄漏跟 aboutToDisappear 里 destroy 不冲突 this.httpRequest?.destroy() this.httpRequest null }) // destroy usingCache priorityusingCache 是 boolean 不是字符串priority 是数字不是字符串鸿蒙 destroy usingCache priority API 真名坑http.HttpRequest.destroy(): void主动销毁 HttpRequest 实例避免内存泄漏跟aboutToDisappear里 destroy 配合HttpRequestOptions.usingCache: boolean是否使用缓存true/false不是字符串force-cache/no-cacheHttpRequestOptions.priority: number优先级数字0最高不是字符串high/lowHttpRequestOptions.connectTimeout: number/readTimeout: number超时毫秒不是 React 的timeout: 5000鸿蒙坑前端fetch的cache: force-cache是字符串鸿蒙usingCache: true是 boolean前端priority不存在fetch 没 priority鸿蒙priority: 0是数字0 最高优先级。五、一句话哲学写鸿蒙 ArkTS 记住http 不是 fetch 是「http.createHttp() 工厂造 HttpRequest 实例 on/off 监听」——鸿蒙 6.1 API 23ohos.net.httpnamespaceAPI 6鸿蒙 6.1 API 23 基座http.createHttp()工厂函数 HttpRequestinterface HttpDataType/RequestMethodenum HttpRequestOptions/HttpResponse类型SysCap SystemCapability.Communication.NetStackatomicservice权限 ohos.permission.INTERNET。根因不是浏览器 API 是 ArkTS 命名空间工厂——HttpDataTypeenum 常量是STRING不是STRING_TYPE✅http.HttpDataType.STRING0/ARRAY_BUFFER1/OBJECT2跟字面量string对应去掉_TYPE后缀❌STRING_TYPE不存在编译错has no exported memberHttpRequest是 interface 不能new✅http.createHttp()工厂函数造实例❌new http.HttpRequest()编译错Cannot use new with an interfaceinterface 没有构造函数on/off监听不是addEventListener/removeEventListener✅httpRequest.on(headersReceive, cb)/off(headersReceive, cb)❌addEventListener/removeEventListener不存在编译错Property does not existoffcallback 必须传同一个引用不是匿名函数HttpRequestOptions.header是Recordstring, string不是Headers对象✅{ Content-Type: application/json }对象字面量❌new Headers()编译错Cannot find name Headers鸿蒙没导出Headers类型RequestMethodenum 常量不是字符串GET✅http.RequestMethod.GET0/POST1/PUT2/DELETE3❌method: GET编译错Type string is not assignable to type RequestMethodrequest方法带回调不是 Promise✅httpRequest.request(url, options, (err, data) {})❌await httpRequest.request(url, options)不返回 PromiseextraData是 POST body 不是body字段前端 fetch 用body鸿蒙用extraDataexpectDataType指定响应类型STRING 返回 string / ARRAY_BUFFER 返回 ArrayBuffer / OBJECT 返回 Objectdestroy()主动销毁避免内存泄漏跟aboutToDisappear配合usingCache是 boolean 不是字符串true/false不是force-cache。HttpDataType STRING 常量 HttpRequest interface 不能 new http.createHttp() 工厂 on/off 监听 header Record RequestMethod enum是鸿蒙 6.1 ohos.net.http HTTP 请求坑核心能力系列回链鸿蒙 7.0 新特性篇 1~17沉浸式毛玻璃/Component3D/智能体框架/方舟引擎/星盾安全/星河互联/空间音频/可变字体/游戏快启/分布式数据盾/LTPO 可变帧率/AI 文档识别/多形态服务窗口/AI 反诈/机密计算/空间计算/小艺全面进化鸿蒙 6.1 API 23 开发坑系列篇 1「ArkUI.modifier 装饰器坑」——attributeModifier AttributeModifier 状态化节点修改器鸿蒙 6.1 API 23 开发坑系列篇 2「arkui.componentSnapshot 组件截图坑」——get/getSync/createFromBuilder 返回 image.PixelMap 像素图鸿蒙 6.1 API 23 开发坑系列篇 3「arkui.node 节点坑」——NodeController abstract class makeNode override BuilderNode WrappedBuilder鸿蒙 6.1 API 23 开发坑系列篇 4「arkui.UIContext UI 上下文坑」——runScopedTask 不是 runScopedOnUiThread 11 个子管理器鸿蒙 6.1 API 23 开发坑系列篇 5「arkui.observer UI 观察器坑」——uiObserver namespace 真名不是 observer on type string literal鸿蒙 6.1 API 23 开发坑系列篇 6「ohos.animator 动画器坑」——import kit.ArkUI 不是 ohos.animator onFrame 驼峰不是废弃 onframe getUIContext().createAnimator 不是废弃 animator.create 持引用 aboutToDisappear cancel鸿蒙 6.1 API 23 开发坑系列篇 7「ohos.net.http HTTP 请求坑」——HttpDataType 常量是 STRING 不是 STRING_TYPE HttpRequest 是 interface 不能 new http.createHttp() 工厂造实例 on/off 监听不是 addEventListener header Record 不是 Headers RequestMethod enum 不是字符串本文