ZEPETO.Multiplay.HttpService
12 min
type description httpcontenttype /#httpcontenttype enumeration of constants specifying the http content type httpbodytype /#httpbodytype type alias for http body content, which can be either plain text or a key value object httpheader /#httpheader type alias for http headers, representing a key value object httperrortype /#httperrortype enumeration of constants specifying reasons for failure in http requests httperror /#httperror represents an error that occurred during an http request httpresponse /#httpresponse represents an http response httpservice /#httpservice httpservice provides an api to establish http connections with external web services and make requests ensure using https protocol; http is supported only in the development environment requests are limited to ports 80 and 443 the maximum size for request and response bodies is 16kb keep requests per minute below 500 to avoid potential limitations on the world service due to excessive requests requests will fail if external web services do not respond within 5 seconds ensure that the content type in response headers matches values defined in httpcontenttype enum to prevent request failures due to potential web request failures for various reasons, it's recommended to code defensively httpcontenttype enum enumeration of constants specifying the http content type name value description applicationjson "application/json" represents application/json content type applicationxml "application/xml" represents application/xml content type applicationurlencoded "application/x www form urlencoded" represents application/x www form urlencoded content type textplain "text/plain" represents text/plain content type textxml "text/xml" represents text/xml content type httpbodytype delegate type alias for http body content, which can be either plain text or a key value object string | { \[key string] any; } httpheader delegate type alias for http headers, representing a key value object { \[key string] string | number; } httperrortype enum enumeration of constants specifying reasons for failure in http requests name value description err access denied "err access denied" error access denied err length required "err length required" error length required httperror interface · extends error represents an error that occurred during an http request properties name type description message string error message code string error code defined as a value from httperrortype enum httpresponse interface represents an http response properties name type description statuscode number the status code of the response typically, 200 indicates a successful request statustext string the status message corresponding to the status code typically, "ok" indicates a successful request response string the body of the http response, which may vary in format based on the response's content type it is recommended to use an appropriate parser based on the specific content type received httpservice interface httpservice provides an api to establish http connections with external web services and make requests ensure using https protocol; http is supported only in the development environment requests are limited to ports 80 and 443 the maximum size for request and response bodies is 16kb keep requests per minute below 500 to avoid potential limitations on the world service due to excessive requests requests will fail if external web services do not respond within 5 seconds ensure that the content type in response headers matches values defined in httpcontenttype enum to prevent request failures due to potential web request failures for various reasons, it's recommended to code defensively methods getasync getasync(url string, headers? httpheader) → promise\<httpresponse> asynchronously performs an http get request throws httperror parameter type description url string the web address to send the request headers (optional) httpheader /#httpheader http request headers (optional) returns promise\<httpresponse> — promise resolved with the httpresponse object upon completion postasync postasync(url string, body httpbodytype, headers? httpheader) → promise\<httpresponse> perform http post requests asynchronously throws httperror parameter type description url string the web address to send the request body httpbodytype /#httpbodytype request body content headers (optional) httpheader /#httpheader http request headers (optional) returns promise\<httpresponse> — promise resolved with the httpresponse object upon completion postasync postasync(url string, body httpbodytype, httpcontenttype httpcontenttype, headers? httpheader) → promise\<httpresponse> perform http post requests asynchronously throws httperror when using this signature, if you add 'content type' to headers, it will be overwritten by what is specified in httpcontenttype parameter type description url string the web address to send the request body httpbodytype /#httpbodytype request body content httpcontenttype httpcontenttype /#httpcontenttype specifies the request content type header headers (optional) httpheader /#httpheader http request headers (optional) returns promise\<httpresponse> — promise resolved with the httpresponse object upon completion
