openharmony 鸿蒙 capi-net-http-type-h

2026-08-25 浏览 (1)

net_http_type.h

Overview

Defines the data structures for the C APIs of the HTTP request module.

File to include: <network/netstack/net_http_type.h>

Library: libnet_http.so

System capability: SystemCapability.Communication.NetStack

Since: 20

Related module: netstack

Summary

Structs

Nametypedef KeywordDescription
Http_BufferHttp_BufferDefines the HTTP buffer structure.
Http_HeaderValueHttp_HeaderValueDefines the type of a mapped value in a request or response header.
Http_HeaderEntryHttp_HeaderEntryDefines all key-value pairs in the request or response header.
Http_ClientCertHttp_ClientCertDefines the client certificate sent to a remote server, which will be used by the server to verify the identity of the client.
Http_CustomProxyHttp_CustomProxyDefines the custom proxy configuration.
Http_ProxyHttp_ProxyDefines the proxy configuration structure.
Http_PerformanceTimingHttp_PerformanceTimingDefines the HTTP response timing information, which will be collected via Http_Response.performanceTiming.
Http_RequestOptionsHttp_RequestOptionsDefines the structure of HTTP requests.
Http_ResponseHttp_ResponseDefines the structure of HTTP responses.
Http_RequestHttp_RequestDefines an HTTP request.
Http_EventsHandlerHttp_EventsHandlerDefines the callback for various HTTP events.
Http_HeadersHttp_HeadersDefines the header of an HTTP request or response.

Enums

Nametypedef KeywordDescription
Http_ErrCodeHttp_ErrCodeEnumerates the error codes of an HTTP request.
Http_ResponseCodeHttp_ResponseCodeEnumerates the result codes of an HTTP response.
Http_AddressFamilyTypeHttp_AddressFamilyTypeEnumerates the IP address family of the target domain name.
Http_HttpProtocolHttp_HttpProtocolEnumerates HTTP protocol versions.
Http_CertTypeHttp_CertTypeEnumerates certificate types.
Http_ProxyTypeHttp_ProxyTypeEnumerates proxy types.

Macros

NameDescription
OHOS_HTTP_MAX_PATH_LEN 128Defines the maximum path length of an HTTP request.
Since: 20
OHOS_HTTP_MAX_STR_LEN 256Defines the maximum string length of an HTTP request.
Since: 20
OHOS_HTTP_DNS_SERVER_NUM_MAX 3Defines the maximum number of DNS servers for an HTTP request.
Since: 20
NET_HTTP_METHOD_GET "GET"Sets the HTTP request method to GET.
Since: 20
NET_HTTPMETHOD_HEAD "HEAD"Sets the HTTP request method to HEAD.
Since: 20
NET_HTTPMETHOD_OPTIONS "OPTIONS"Sets the HTTP request method to OPTIONS.
Since: 20
NET_HTTPMETHOD_TRACE "TRACE"Sets the HTTP request method to TRACE.
Since: 20
NET_HTTPMETHOD_DELETE "DELETE"Sets the HTTP request method to DELETE.
Since: 20
NET_HTTP_METHOD_POST "POST"Sets the HTTP request method to POST.
Since: 20
NET_HTTP_METHOD_PUT "PUT"Sets the HTTP request method to PUT.
Since: 20
NET_HTTP_METHOD_PATCH "CONNECT"Sets the HTTP request method to CONNECT.
Since: 20

Functions

Nametypedef KeywordDescription
typedef void (*Http_ResponseCallback)(struct Http_Response *response, uint32_t errCode)Http_ResponseCallbackCallback invoked when an HTTP response is received.
typedef void (*Http_OnDataReceiveCallback)(const char *data, size_t length)Http_OnDataReceiveCallbackCallback invoked when data is received.
typedef void (*Http_OnProgressCallback)(uint64_t totalSize, uint64_t transferredSize)Http_OnProgressCallbackCallback invoked during request/response data transmission.
typedef void (*Http_OnHeaderReceiveCallback)(Http_Headers *headers)Http_OnHeaderReceiveCallbackCallback invoked when an HTTP response header is received.
typedef void (*Http_OnVoidCallback)(void)Http_OnVoidCallbackCallback invoked when a DataEnd or Cancel event is received.

Enum Description

Http_ErrCode

enum Http_ErrCode

Overview

Enumerates the error codes of an HTTP request.

Since: 20

EnumDescription
OH_HTTP_RESULT_OK = 0Request succeeded.
OH_HTTP_PARAMETER_ERROR = 401Invalid parameter.
OH_HTTP_PERMISSION_DENIED = 201Permission denied.
OH_HTTP_NETSTACK_E_BASE = 2300000Base error code offset.
OH_HTTP_UNSUPPORTED_PROTOCOL = (OH_HTTP_NETSTACK_E_BASE + 1)Unsupported protocol.
OH_HTTP_INVALID_URL = (OH_HTTP_NETSTACK_E_BASE + 3)Incorrect URL format.
OH_HTTP_RESOLVE_PROXY_FAILED = (OH_HTTP_NETSTACK_E_BASE + 5)Failed to resolve the domain name of the proxy server.
OH_HTTP_RESOLVE_HOST_FAILED = (OH_HTTP_NETSTACK_E_BASE + 6)Failed to resolve the domain name.
OH_HTTP_CONNECT_SERVER_FAILED = (OH_HTTP_NETSTACK_E_BASE + 7)Failed to connect to the server.
OH_HTTP_INVALID_SERVER_RESPONSE = (OH_HTTP_NETSTACK_E_BASE + 8)Invalid data returned by the server.
OH_HTTP_ACCESS_REMOTE_DENIED = (OH_HTTP_NETSTACK_E_BASE + 9)Access to remote resources denied.
OH_HTTP_HTTP2_FRAMING_ERROR = (OH_HTTP_NETSTACK_E_BASE + 16)Error detected at the HTTP2 framework layer.
OH_HTTP_TRANSFER_PARTIAL_FILE = (OH_HTTP_NETSTACK_E_BASE + 18)Files partially transferred.
OH_HTTP_WRITE_DATA_FAILED = (OH_HTTP_NETSTACK_E_BASE + 23)Failed to write the received data to the disk or application.
OH_HTTP_UPLOAD_FAILED = (OH_HTTP_NETSTACK_E_BASE + 25)Failed to upload data.
OH_HTTP_OPEN_LOCAL_DATA_FAILED = (OH_HTTP_NETSTACK_E_BASE + 26)Failed to open or read the local data in the file or application.
OH_HTTP_OUT_OF_MEMORY = (OH_HTTP_NETSTACK_E_BASE + 27)Insufficient memory.
OH_HTTP_OPERATION_TIMEOUT = (OH_HTTP_NETSTACK_E_BASE + 28)Operation timeout.
OH_HTTP_TOO_MANY_REDIRECTIONS = (OH_HTTP_NETSTACK_E_BASE + 47)Number of redirections reaching the maximum.
OH_HTTP_SERVER_RETURNED_NOTHING = (OH_HTTP_NETSTACK_E_BASE + 52)No content (header or data) returned by the server.
OH_HTTP_SEND_DATA_FAILED = (OH_HTTP_NETSTACK_E_BASE + 55)Failed to send data via Bluetooth.
OH_HTTP_RECEIVE_DATA_FAILED = (OH_HTTP_NETSTACK_E_BASE + 56)Failed to receive data.
OH_HTTP_SSL_CERTIFICATE_ERROR = (OH_HTTP_NETSTACK_E_BASE + 58)Invalid local SSL certificate.
OH_HTTP_SSL_CIPHER_USED_ERROR = (OH_HTTP_NETSTACK_E_BASE + 59)Specified cipher suite unavailable.
OH_HTTP_INVALID_SSL_PEER_CERT = (OH_HTTP_NETSTACK_E_BASE + 60)Invalid SSL peer certificate or SSH remote key.
OH_HTTP_INVALID_ENCODING_FORMAT = (OH_HTTP_NETSTACK_E_BASE + 61)Invalid HTTP encoding format.
OH_HTTP_FILE_TOO_LARGE = (OH_HTTP_NETSTACK_E_BASE + 63)Maximum file size exceeded.
OH_HTTP_REMOTE_DISK_FULL = (OH_HTTP_NETSTACK_E_BASE + 70)Remote disk fully occupied.
OH_HTTP_REMOTE_FILE_EXISTS = (OH_HTTP_NETSTACK_E_BASE + 73)Remote file already exists.
OH_HTTP_SSL_CA_NOT_EXIST = (OH_HTTP_NETSTACK_E_BASE + 77)SSL CA certificate inexistent or inaccessible.
OH_HTTP_REMOTE_FILE_NOT_FOUND = (OH_HTTP_NETSTACK_E_BASE + 78)Remote file not found.
OH_HTTP_AUTHENTICATION_ERROR = (OH_HTTP_NETSTACK_E_BASE + 94)Identity authentication error.
OH_HTTP_ACCESS_DOMAIN_NOT_ALLOWED = (OH_HTTP_NETSTACK_E_BASE + 998)Access to the domain denied.
OH_HTTP_UNKNOWN_ERROR = (OH_HTTP_NETSTACK_E_BASE + 999)Unknown error.

Http_ResponseCode

enum Http_ResponseCode

Overview

Enumerates the result codes of an HTTP response.

Since: 20

EnumDescription
OH_HTTP_OK = 200Request succeeded.
OH_HTTP_CREATED = 201"Created." The request has been successfully sent and a new resource is created.
OH_HTTP_ACCEPTED = 202"Accepted." The request has been accepted for processing, but the processing has not been completed.
OH_HTTP_NON_AUTHORITATIVE_INFO = 203"Non-Authoritative Information." The request was successfully processed, but the returned response body contains non-authoritative information.
OH_HTTP_NO_CONTENT = 204"No Content." The server has successfully fulfilled the request but there is no additional content to send in the response payload body.
OH_HTTP_RESET = 205"Reset Content." The server has successfully fulfilled the request and desires that the user agent reset the content.
OH_HTTP_PARTIAL = 206"Partial Content." The server has successfully fulfilled the partial GET request for a given resource.
OH_HTTP_MULTI_CHOICE = 300"Multiple Choices." The requested resource corresponds to any one of a set of representations.
OH_HTTP_MOVED_PERM = 301"Moved Permanently." The requested resource has been assigned a new permanent URI and any future references to this resource will be redirected to this URI.
OH_HTTP_MOVED_TEMP = 302"Moved Temporarily." The requested resource is moved temporarily to a different URI.
OH_HTTP_SEE_OTHER = 303"See Other." The response to the request can be found under a different URI.
OH_HTTP_NOT_MODIFIED = 304"Not Modified." The client has performed a conditional GET request and access is allowed, but the content has not been modified.
OH_HTTP_USE_PROXY = 305"Use Proxy." The requested resource can only be accessed through the proxy.
OH_HTTP_BAD_REQUEST = 400"Bad Request." The request could not be understood by the server due to incorrect syntax.
OH_HTTP_UNAUTHORIZED = 401"Unauthorized." The request requires user authentication.
OH_HTTP_PAYMENT_REQUIRED = 402"Payment Required." This code is reserved for future use.
OH_HTTP_FORBIDDEN = 403"Forbidden." The server understands the request but refuses to process it.
OH_HTTP_NOT_FOUND = 404"Not Found." The server does not find anything matching the Request-URI.
OH_HTTP_BAD_METHOD = 405"Method Not Allowed." The method specified in the request is not allowed for the resource identified by the Request-URI.
OH_HTTP_NOT_ACCEPTABLE = 406"Not Acceptable." The server cannot fulfill the request according to the content characteristics of the request.
OH_HTTP_PROXY_AUTH = 407"Proxy Authentication Required." The request requires user authentication with the proxy.
OH_HTTP_CLIENT_TIMEOUT = 408"Request Timeout." The client fails to generate a request within the timeout period.
OH_HTTP_CONFLICT = 409"Conflict." The request cannot be fulfilled due to a conflict with the current state of the resource. Conflicts are most likely to occur in response to a PUT request.
OH_HTTP_GONE = 410"Gone." The requested resource has been deleted permanently and is no longer available.
OH_HTTP_LENGTH_REQUIRED = 411"Length Required." The server refuses to process the request without a defined Content-Length.
OH_HTTP_PRECON_FAILED = 412"Precondition Failed." The precondition in the request is incorrect.
OH_HTTP_ENTITY_TOO_LARGE = 413"Request Entity Too Large." The server refuses to process a request because the request entity is larger than the server is able to process.
OH_HTTP_REQUEST_TOO_LONG = 414"Request-URI Too Long." The Request-URI is too long for the server to process.
OH_HTTP_UNSUPPORTED_TYPE = 415"Unsupported Media Type." The server is unable to process the media format in the request.
OH_HTTP_RANGE_NOT_MET = 416"Range Not Satisfiable." The server cannot serve the requested ranges.
OH_HTTP_INTERNAL_ERROR = 500"Internal Server Error." The server encounters an unexpected error that prevents it from fulfilling the request.
OH_HTTP_NOT_IMPLEMENTED = 501"Not Implemented." The server does not support the function required to fulfill the request.
OH_HTTP_BAD_GATEWAY = 502"Bad Gateway." The server acting as a gateway or proxy receives an invalid response from the upstream server.
OH_HTTP_UNAVAILABLE = 503"Service Unavailable." The server is currently unable to process the request due to a temporary overload or system maintenance.
OH_HTTP_GATEWAY_TIMEOUT = 504"Gateway Timeout." The server acting as a gateway or proxy does not receive requests from the remote server within the timeout period.
OH_HTTP_VERSION = 505"HTTP Version Not Supported." The server does not support the HTTP protocol version used in the request.

Http_AddressFamilyType

enum Http_AddressFamilyType

Overview

Enumerates the IP address family of the target domain name.

Since: 20

EnumDescription
HTTP_ADDRESS_FAMILY_DEFAULT = 0Default value. The system determines whether to use the IPv4 or IPv6 address of the target domain name.
HTTP_ADDRESS_FAMILY_ONLY_V4 = 1The system resolves only the IPv4 address of the target domain name and ignores the IPv6 address.
HTTP_ADDRESS_FAMILY_ONLY_V6 = 2The system resolves only the IPv6 address of the target domain name and ignores the IPv4 address.

Http_HttpProtocol

enum Http_HttpProtocol

Overview

Enumerates HTTP protocol versions.

Since: 20

EnumDescription
OH_HTTP_NONE = 0Protocol version complies with cURL.
OH_HTTP1_1HTTP 1.1 version.
OH_HTTP2HTTP 2 version.
OH_HTTP3HTTP 3 version.

Http_CertType

enum Http_CertType

Overview

Enumerates certificate types.

Since: 20

EnumDescription
OH_HTTP_PEM = 0PEM certificate.
OH_HTTP_DER = 1DER certificate.
OH_HTTP_P12 = 2P12 certificate.

Http_ProxyType

enum Http_ProxyType

Overview

Enumerates proxy types.

Since: 20

EnumDescription
HTTP_PROXY_NOT_USENo proxy.
HTTP_PROXY_SYSTEMThe system proxy is used.
HTTP_PROXY_CUSTOMThe custom proxy is used.

Function Description

Http_ResponseCallback()

typedef void (*Http_ResponseCallback)(struct Http_Response *response, uint32_t errCode)

Overview

Callback invoked when an HTTP response is received.

Since: 20

Parameters

NameDescription
struct Http_Response *responsePointer to the HTTP response. For details, see Http_Response.
uint32_t errCodeResponse code.

Http_OnDataReceiveCallback()

typedef void (*Http_OnDataReceiveCallback)(const char *data, size_t length)

Overview

Callback invoked when data is received.

Since: 20

Parameters

NameDescription
const char *dataResponse body.
size_t lengthLength of the response body.

Http_OnProgressCallback()

typedef void (*Http_OnProgressCallback)(uint64_t totalSize, uint64_t transferredSize)

Overview

Callback invoked during request/response data transmission.

Since: 20

Parameters

NameDescription
uint64_t totalSizeTotal data size.
uint64_t transferredSizeSize of transferred data.

Http_OnHeaderReceiveCallback()

typedef void (*Http_OnHeaderReceiveCallback)(Http_Headers *headers)

Overview

Callback invoked when an HTTP response header is received.

Since: 20

Parameters

NameDescription
Http_Headers *headersPointer to the received request header. For details, see Http_Headers.

Http_OnVoidCallback()

typedef void (*Http_OnVoidCallback)(void)

Overview

Callback invoked when a DataEnd or Cancel event is received.

Since: 20

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-netconnection-netconn-connectionproperties

openharmony 鸿蒙 errorcode-net-mdns

openharmony 鸿蒙 js-apis-net-ethernet-sys

openharmony 鸿蒙 errorcode-net-http

openharmony 鸿蒙 capi-netstack-http-proxy

openharmony 鸿蒙 js-apis-system-fetch

openharmony 鸿蒙 errorcode-kernel

openharmony 鸿蒙 capi-netstack-netstack-certblob

openharmony 鸿蒙 js-apis-net-mdns

openharmony 鸿蒙 capi-netstack-websocket-closeoption

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/RE9XIm9Z