文档文档

requests.get() 函数

requests.get() 发起一个 http GET 请求。这与调用 request.do(method: "GET", ...) 完全相同。

函数类型签名
(
    url: string,
    ?body: bytes,
    ?config: {A with timeout: duration, insecureSkipVerify: bool},
    ?headers: [string:string],
    ?params: [string:[string]],
) => {statusCode: int, headers: [string:string], duration: duration, body: bytes}

更多信息,请参阅 函数类型签名

参数

url

(必需) 要请求的 URL。这不应包含任何查询参数。

params

要添加到 URL 作为查询参数的键值对集合。查询参数将被 URL 编码。一个键的所有值都将附加到查询中。

headers

要包含在请求中的键值对集合。

body

随请求发送的数据。

config

用于控制请求应如何执行的选项集合。

示例

发起 GET 请求

import "http/requests"

response = requests.get(url: "http://example.com")

requests.peek(response: response)

发起 GET 请求并解码 JSON 响应

import "http/requests"
import "experimental/json"
import "array"

response = requests.get(url: "https://api.agify.io", params: ["name": ["nathaniel"]])

// api.agify.io returns JSON with the form
//
// {
//    name: string,
//    age: number,
//    count: number,
// }
//
// Define a data variable that parses the JSON response body into a Flux record.
data = json.parse(data: response.body)

// Use array.from() to construct a table with one row containing our response data.
// We do not care about the count so only include name and age.
array.from(rows: [{name: data.name, age: data.age}])

查看示例输出


此页是否对您有帮助?

感谢您的反馈!


Flux 的未来

Flux 即将进入维护模式。您可以继续像目前一样使用它,而无需对您的代码进行任何更改。

阅读更多

现已全面上市

InfluxDB 3 Core 和 Enterprise

快速启动。更快扩展。

获取更新

InfluxDB 3 Core 是一个开源、高速、近实时数据引擎,可实时收集和处理数据,并将其持久化到本地磁盘或对象存储。InfluxDB 3 Enterprise 构建在 Core 的基础上,增加了高可用性、读取副本、增强的安全性以及数据压缩,以实现更快的查询和优化的存储。InfluxDB 3 Enterprise 的免费层可供非商业家庭或业余爱好者使用。

有关更多信息,请查看