目录

http_interceptor.h

概述

定义HTTP全局拦截器模块的接口,分为只读拦截器与可修改拦截器两类。通过全局只读拦截器,开发者可以监控应用内部通过所支持的系统网络组件发起的所有HTTP请求,实现日志记录功能,也可以在全局可修改拦截器中添加自定义逻辑,修改应用内部通过所支持的系统网络组件发起的HTTP请求的请求头、响应头、响应体。

引用文件: <network/netstack/http_interceptor.h>

库: libhttp_interceptor.so

系统能力: SystemCapability.Communication.NetStack

起始版本: 24

相关模块: netstack

汇总

[h2]函数

名称 描述
int32_t OH_Http_AddReadOnlyInterceptor(struct OH_Http_Interceptor *interceptor) 添加一个HTTP全局只读拦截器。
int32_t OH_Http_AddWritableInterceptor(struct OH_Http_Interceptor *interceptor) 添加一个HTTP全局可修改拦截器。
int32_t OH_Http_RemoveInterceptor(struct OH_Http_Interceptor *interceptor) 删除指定的HTTP全局拦截器。
int32_t OH_Http_RemoveAllInterceptors(int32_t groupId) 删除指定组ID的所有HTTP拦截器。
int32_t OH_Http_StartAllInterceptors(int32_t groupId) 启用指定组ID的所有HTTP拦截器。
int32_t OH_Http_StopAllInterceptors(int32_t groupId) 停用指定组ID的所有HTTP拦截器。

函数说明

[h2]OH_Http_AddReadOnlyInterceptor()

int32_t OH_Http_AddReadOnlyInterceptor(struct OH_Http_Interceptor *interceptor)

描述

添加一个HTTP全局只读拦截器。

系统能力: SystemCapability.Communication.NetStack

需要权限: ohos.permission.INTERNET

起始版本: 24

参数:

参数项 描述
struct OH_Http_Interceptor *interceptor 待添加的拦截器,指向OH_Http_Interceptor结构体的指针。

返回:

类型 说明
int32_t 返回值为0表示执行成功;返回值为201表示权限被拒绝;返回值为401表示参数错误(如指针为nullptr,或不支持所添加的拦截器类型)。详细错误码请参考OH_HTTP_RESULT_OK、OH_HTTP_PERMISSION_DENIED和OH_HTTP_PARAMETER_ERROR。

[h2]OH_Http_AddWritableInterceptor()

int32_t OH_Http_AddWritableInterceptor(struct OH_Http_Interceptor *interceptor)

描述

添加一个HTTP全局可修改拦截器。

系统能力: SystemCapability.Communication.NetStack

需要权限: ohos.permission.INTERNET

起始版本: 26.0.0

参数:

参数项 描述
struct OH_Http_Interceptor *interceptor 待添加的拦截器,指向OH_Http_Interceptor结构体的指针。

返回:

类型 说明
int32_t 返回值为0表示执行成功;返回值为201表示权限被拒绝;返回值为401表示参数错误(如指针为nullptr,或不支持所添加的拦截器类型)。详细错误码请参考OH_HTTP_RESULT_OK、OH_HTTP_PERMISSION_DENIED和OH_HTTP_PARAMETER_ERROR。

[h2]OH_Http_RemoveInterceptor()

int32_t OH_Http_RemoveInterceptor(struct OH_Http_Interceptor *interceptor)

描述

删除指定的HTTP全局拦截器。

系统能力: SystemCapability.Communication.NetStack

需要权限: ohos.permission.INTERNET

起始版本: 24

参数:

参数项 描述
struct OH_Http_Interceptor *interceptor 待删除的拦截器,指向OH_Http_Interceptor结构体的指针。

返回:

类型 说明
int32_t 返回值为0表示执行成功;返回值为201表示权限被拒绝;返回值为401表示参数错误(如指针为 nullptr)。详细错误码请参考OH_HTTP_RESULT_OK、OH_HTTP_PERMISSION_DENIED和OH_HTTP_PARAMETER_ERROR。

[h2]OH_Http_RemoveAllInterceptors()

int32_t OH_Http_RemoveAllInterceptors(int32_t groupId)

描述

删除指定组ID的所有HTTP拦截器。

系统能力: SystemCapability.Communication.NetStack

需要权限: ohos.permission.INTERNET

起始版本: 24

参数:

参数项 描述
int32_t groupId 拦截器组ID。

返回:

类型 说明
int32_t 返回值为0表示执行成功;返回值为201表示权限被拒绝。详细错误码请参考OH_HTTP_RESULT_OK和OH_HTTP_PERMISSION_DENIED。

[h2]OH_Http_StartAllInterceptors()

int32_t OH_Http_StartAllInterceptors(int32_t groupId)

描述

启用指定组ID的所有HTTP拦截器。

系统能力: SystemCapability.Communication.NetStack

需要权限: ohos.permission.INTERNET

起始版本: 24

参数:

参数项 描述
int32_t groupId 拦截器组ID。

返回:

类型 说明
int32_t 返回值为0表示执行成功;返回值为201表示权限被拒绝。详细错误码请参考OH_HTTP_RESULT_OK和OH_HTTP_PERMISSION_DENIED。

[h2]OH_Http_StopAllInterceptors()

int32_t OH_Http_StopAllInterceptors(int32_t groupId)

描述

停用指定组ID的所有HTTP拦截器。

系统能力: SystemCapability.Communication.NetStack

需要权限: ohos.permission.INTERNET

起始版本: 24

参数:

参数项 描述
int32_t groupId 拦截器组ID。

返回:

类型 说明
int32_t 返回值为0表示执行成功;返回值为201表示权限被拒绝。详细错误码请参考OH_HTTP_RESULT_OK和OH_HTTP_PERMISSION_DENIED。