requests.do() 函数
requests.do()
是实验性的,并且随时可能更改。
requests.do()
发出 http 请求。
已弃用
实验性的 requests.do
已弃用,推荐使用 requests.do
。
返回的响应包含以下属性
- statusCode: 从请求返回的 HTTP 状态代码。
- body: 请求的内容。将从响应正文中读取最大 100MB 的大小。
- headers: 响应中存在的标头。
- duration: 请求的持续时间。
函数类型签名
(
method: string,
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}
有关更多信息,请参阅函数类型签名。
参数
method
(必需)http 请求的方法。支持的方法:DELETE、GET、HEAD、PATCH、POST、PUT。
url
(必需)要请求的 URL。这不应包含任何查询参数。
params
要添加到 URL 作为查询参数的键值对集合。查询参数将被 URL 编码。键的所有值都将附加到查询中。
headers
要包含在请求中的键值对集合。
body
要随请求发送的数据。
config
用于控制应如何执行请求的选项集。
示例
发出 GET 请求
import "experimental/http/requests"
response = requests.do(url: "http://example.com", method: "GET")
requests.peek(response: response)
发出需要授权的 GET 请求
import "experimental/http/requests"
import "influxdata/influxdb/secrets"
token = secrets.get(key: "TOKEN")
response =
requests.do(
method: "GET",
url: "http://example.com",
headers: ["Authorization": "token ${token}"],
)
requests.peek(response: response)
发出带有查询参数的 GET 请求
import "experimental/http/requests"
response = requests.do(method: "GET", url: "http://example.com", params: ["start": ["100"]])
requests.peek(response: response)
此页是否对您有帮助?
谢谢您的反馈!