AnyMath 文档

HTTP软件管理

此页面包含所有可用的HTTP软件管理功能 AnyMath.

使用http软件管理功能 AnyMath,按照在给出的说明 文章.

function close_session(device::HttpType)::Nothing

销毁先前创建的 HTTP 客户端。

参数device::HttpType :HTTP.Http() 类型的对象。

function delete(device::HttpType, endpoint::String, request_data::HTTPRequestData, headers::Dict{String, String}=Dict(), timeout::Union{Int64, Nothing}=nothing)::HTTPResponse

REST API 的 DELETE 请求。返回HTTPResponse ---- 包含服务器响应的对象,其中包含:

  • text_content :文本格式的 HTTP 响应;

  • bytes_content :字节格式的 HTTP 响应;

  • elapsed :请求执行时间;

  • status_code :HTTP 请求的状态码。

服务器响应示例

Base.@kwdef struct HTTPResponse
text_content::Union{String, Nothing} = nothing
bytes_content::Union{Vector{UInt8}, Nothing} = nothing
elapsed::Union{HTTPTimedelta, Nothing} = nothing
status_code::Union{Int64, Nothing} = nothing
end

参数

  • device::HttpType : HTTP.Http() 类型的对象。

  • endpoint::String : 用于访问 HTTP 资源的端点。

  • request_data::HTTPRequestData : 请求数据(类型为 HTTPRequestData 的对象)。

  • headers::Dict{String, String} : 附加头部。例如,配置连接头部和请求的 MIME 类型:

    headers = Dict{String, String}()
    headers["connection"] = "keep-alive"
    headers["Accept"] = "application/json"
  • timeout::Union{Int64, Nothing} : 等待响应的超时时间(单位:秒)。

function get(device::HttpType, endpoint::String, request_data::HTTPRequestData, headers::Dict{String, String}=Dict(), timeout::Union{Int64, Nothing}=nothing)::HTTPResponse

REST API 的 GET 请求。返回HTTPResponse ---- 包含服务器响应的对象,其中包含:

  • text_content :文本格式的 HTTP 响应;

  • bytes_content :字节格式的 HTTP 响应;

  • elapsed :请求执行时间;

  • status_code :HTTP 请求的状态码。

服务器响应示例

Base.@kwdef struct HTTPResponse
text_content::Union{String, Nothing} = nothing
bytes_content::Union{Vector{UInt8}, Nothing} = nothing
elapsed::Union{HTTPTimedelta, Nothing} = nothing
status_code::Union{Int64, Nothing} = nothing
end

参数

  • device::HttpType : 类型为 HTTP.Http() 的对象。

  • endpoint::String : 用于访问 HTTP 资源的端点。

  • request_data::HTTPRequestData : 类型为 HTTPRequestData 的对象。

  • headers::Dict{String, String} :附加头部。例如,配置连接头部和请求的 MIME 类型:

    headers = Dict{String, String}()
    headers["connection"] = "keep-alive"
    headers["Accept"] = "application/json"
  • timeout::Union{Int64, Nothing} :等待响应的超时时间(以秒为单位)。

function init_session(device::HttpType, base_url::String="", auth::Union{Tuple{String}, String, Nothing}=nothing, auth_type::String="bearer", headers::Dict{String, String}=Dict(), timeout::Int64=30, verify_ssl::Bool=true)::Bool

初始化 HTTP 客户端以与 HTTP 服务器通信。

参数

  • device::HttpType : HTTP.Http() 类型的对象。

  • base_url::String : 所有请求的基础 URL。

  • auth::Union{Tuple{String} : 授权数据,可以是元组(username, password),也可以是包含令牌的字符串。

  • auth_type::String : 身份验证类型(basicdigestbearer )。

  • headers::Dict{String, String} :要包含在每个请求中的默认标头。

  • timeout::Int64 :默认响应超时时间(单位:秒)。

  • verify_ssl::Bool :SSL证书验证(true — 启用,false — 禁用)。

function patch(device::HttpType, endpoint::String, request_data::HTTPRequestData, headers::Dict{String, String}=Dict(), timeout::Union{Int64, Nothing}=nothing)::HTTPResponse

REST API 的 PATCH 请求。返回HTTPResponse — 包含服务器响应的对象,其中包含:

  • text_content :文本格式的 HTTP 响应;

  • bytes_content :字节格式的 HTTP 响应;

  • elapsed :请求执行时间;

  • status_code :HTTP 请求的状态码。

服务器响应示例

Base.@kwdef struct HTTPResponse
text_content::Union{String, Nothing} = nothing
bytes_content::Union{Vector{UInt8}, Nothing} = nothing
elapsed::Union{HTTPTimedelta, Nothing} = nothing
status_code::Union{Int64, Nothing} = nothing
end

参数

  • device::HttpType : 类型为 HTTP.Http() 的对象。

  • endpoint::String : 用于访问 HTTP 资源的端点。

  • request_data::HTTPRequestData :HTTPRequestData 类型的对象。

  • headers::Dict{String, String} :附加头部。例如,配置连接头部和请求的 MIME 类型:

    headers = Dict{String, String}()
    headers["connection"] = "keep-alive"
    headers["Accept"] = "application/json"
  • timeout::Union{Int64, Nothing} :等待响应的超时时间(单位:秒)。

function post(device::HttpType, endpoint::String, request_data::HTTPRequestData, headers::Dict{String, String}=Dict(), timeout::Union{Int64, Nothing}=nothing)::HTTPResponse

REST API 的 POST 请求。 返回HTTPResponse ---- 包含服务器响应的对象,其中包含:

  • text_content :文本格式的 HTTP 响应;

  • bytes_content :字节格式的 HTTP 响应;

  • elapsed :请求执行时间;

  • status_code :HTTP 请求的状态码。

服务器响应示例

Base.@kwdef struct HTTPResponse
text_content::Union{String, Nothing} = nothing
bytes_content::Union{Vector{UInt8}, Nothing} = nothing
elapsed::Union{HTTPTimedelta, Nothing} = nothing
status_code::Union{Int64, Nothing} = nothing
end

参数

  • device::HttpType : HTTP.Http() 类型的对象。

  • endpoint::String : 访问 HTTP 资源的端点。

  • request_data::HTTPRequestData : HTTPRequestData 类型的对象。

  • headers::Dict{String, String} : 附加头部。例如,配置连接头部和请求的 MIME 类型:

    headers = Dict{String, String}()
    headers["connection"] = "keep-alive"
    headers["Accept"] = "application/json"
  • timeout::Union{Int64, Nothing} :等待响应的超时时间(单位为秒)。

function put(device::HttpType, endpoint::String, request_data::HTTPRequestData, headers::Dict{String, String}=Dict(), timeout::Union{Int64, Nothing}=nothing)::HTTPResponse

REST API 的 PUT 请求。返回HTTPResponse ----包含服务器响应的对象,其中包含:

  • text_content :文本格式的 HTTP 响应;

  • bytes_content :以字节形式表示的 HTTP 响应;

  • elapsed :请求的执行时间;

  • status_code :HTTP 请求的状态码。

服务器响应示例

Base.@kwdef struct HTTPResponse
text_content::Union{String, Nothing} = nothing
bytes_content::Union{Vector{UInt8}, Nothing} = nothing
elapsed::Union{HTTPTimedelta, Nothing} = nothing
status_code::Union{Int64, Nothing} = nothing
end

参数

  • device::HttpType :类型为 HTTP.Http() 的对象。

  • endpoint::String :用于访问 HTTP 资源的端点。

  • request_data::HTTPRequestData :类型为 HTTPRequestData 的对象。

  • headers::Dict{String, String} :附加头部。例如,配置连接头部和请求的 MIME 类型:

    headers = Dict{String, String}()
    headers["connection"] = "keep-alive"
    headers["Accept"] = "application/json"
  • timeout::Union{Int64, Nothing} :等待响应的超时时间(单位:秒)。

function remove_header(device::HttpType, key::String)::Nothing

用于从现有请求头中删除指定请求头的函数。

参数

  • device::HttpType : 类型为 HTTP.Http() 的对象。

  • key::String : 要设置的请求头的键。

function set_header(device::HttpType, key::String, value::String)::Nothing

用于在现有请求头的基础上追加请求头的函数。

参数

  • device::HttpType : HTTP.Http() 类型的对象。

  • key::String : 要设置的请求头的键。