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

DELETE是REST API请求。 申报表 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}:授权数据,可以是元组(用户名、密码),也可以是带有令牌的字符串。

  • auth_type::String:认证类型(basic, digest,或 bearer).

  • 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的补丁请求。 申报表 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:要设置的请求头的键。