Solana 文档基础设施即代码标准库

标准操作

这些操作作为标准库的一部分,在所有 Runbooks 中均可使用。

send_http_request

std::send_http_request 操作向指定的 URL 发送 HTTP 请求。

输入

名称是否必填类型描述
url必填string请求发送的目标 URL
method可选stringHTTP 方法(GET、POST、PUT、DELETE),默认值:GET
headers可选map请求中包含的 HTTP 标头
body可选string请求正文(用于 POST/PUT 请求)
timeout_ms可选integer请求超时时间(毫秒)

输出

名称类型描述
status_codeintegerHTTP 状态码
bodystring响应正文
headersmap响应标头
action "api_call" "std::send_http_request" {
description = "Fetch data from API"
url = "https://api.example.com/data"
method = "GET"
headers = {
"Authorization" = "Bearer ${variable.token}"
}
}
output "response" {
value = action.api_call.body
}
output "status" {
value = action.api_call.status_code
}

POST 请求示例

action "create_resource" "std::send_http_request" {
description = "Create a new resource"
url = "https://api.example.com/resources"
method = "POST"
headers = {
"Content-Type" = "application/json"
}
body = {
"name" = variable.name,
"value" = variable.value
}
}

Is this page helpful?

Table of Contents

Edit Page
©️ 2026 Solana 基金会版权所有