ZEPETO.Multiplay.HttpService
11 分
类型 说明 httpcontenttype /#httpcontenttype 用于指定 http content type 的常量枚举。 httpbodytype /#httpbodytype http 请求体内容的类型别名,可以是纯文本或键值对象。 httpheader /#httpheader http 请求头的类型别名,表示一个键值对象。 httperrortype /#httperrortype 用于指定 http 请求失败原因的常量枚举。 httperror /#httperror 表示 http 请求过程中发生的错误。 httpresponse /#httpresponse 表示 http 响应。 httpservice /#httpservice httpservice 提供用于与外部 web 服务建立 http 连接并发起请求的 api。 请确保使用 https 协议;http 仅在开发环境中受支持。 请求仅限于 80 和 443 端口。 请求体和响应体的最大大小为 16kb。 请将每分钟请求数控制在 500 以下,以免因请求过多导致 world 服务受到限制。 若外部 web 服务未在 5 秒内响应,请求将失败。 请确保响应头中的 content type 与 httpcontenttype 枚举中定义的值一致,以避免请求失败。 由于 web 请求可能因各种原因失败,建议采用防御性编程。 httpcontenttype enum 用于指定 http content type 的常量枚举。 名称 值 说明 applicationjson "application/json" 表示 application/json 内容类型。 applicationxml "application/xml" 表示 application/xml 内容类型。 applicationurlencoded "application/x www form urlencoded" 表示 application/x www form urlencoded 内容类型。 textplain "text/plain" 表示 text/plain 内容类型。 textxml "text/xml" 表示 text/xml 内容类型。 httpbodytype delegate http 请求体内容的类型别名,可以是纯文本或键值对象。 string | { \[key string] any; } httpheader delegate http 请求头的类型别名,表示一个键值对象。 { \[key string] string | number; } httperrortype enum 用于指定 http 请求失败原因的常量枚举。 名称 值 说明 err access denied "err access denied" 错误:访问被拒绝。 err length required "err length required" 错误:需要指定长度。 httperror interface · extends error 表示 http 请求过程中发生的错误。 属性 名称 类型 说明 message string 错误消息。 code string 以 httperrortype 枚举中的值定义的错误代码。 httpresponse interface 表示 http 响应。 属性 名称 类型 说明 statuscode number 响应的状态码。通常 200 表示请求成功。 statustext string 与状态码相对应的状态消息。通常 "ok" 表示请求成功。 response string http 响应的正文,其格式可能因响应的 content type 而异。建议根据实际接收到的 content type 使用相应的解析器。 httpservice interface httpservice 提供用于与外部 web 服务建立 http 连接并发起请求的 api。 请确保使用 https 协议;http 仅在开发环境中受支持。 请求仅限于 80 和 443 端口。 请求体和响应体的最大大小为 16kb。 请将每分钟请求数控制在 500 以下,以免因请求过多导致 world 服务受到限制。 若外部 web 服务未在 5 秒内响应,请求将失败。 请确保响应头中的 content type 与 httpcontenttype 枚举中定义的值一致,以避免请求失败。 由于 web 请求可能因各种原因失败,建议采用防御性编程。 方法 getasync getasync(url string, headers? httpheader) → promise\<httpresponse> 以异步方式执行 http get 请求。会抛出 httperror 。 参数 类型 说明 url string 发送请求的目标网址。 headers (可选) httpheader /#httpheader http 请求头。(可选) 返回值: promise\<httpresponse> — 处理完成时兑现的 promise ,携带 httpresponse 对象。 postasync postasync(url string, body httpbodytype, headers? httpheader) → promise\<httpresponse> 以异步方式执行 http post 请求。会抛出 httperror 。 参数 类型 说明 url string 发送请求的目标网址。 body httpbodytype /#httpbodytype 请求体内容。 headers (可选) httpheader /#httpheader http 请求头。(可选) 返回值: promise\<httpresponse> — 处理完成时兑现的 promise ,携带 httpresponse 对象。 postasync postasync(url string, body httpbodytype, httpcontenttype httpcontenttype, headers? httpheader) → promise\<httpresponse> 以异步方式执行 http post 请求。会抛出 httperror 。 使用该签名时,即便在 headers 中添加 'content type',也会被 httpcontenttype 中指定的值覆盖。 参数 类型 说明 url string 发送请求的目标网址。 body httpbodytype /#httpbodytype 请求体内容。 httpcontenttype httpcontenttype /#httpcontenttype 指定请求的 content type 请求头。 headers (可选) httpheader /#httpheader http 请求头。(可选) 返回值: promise\<httpresponse> — 处理完成时兑现的 promise ,携带 httpresponse 对象。
