requests.get() 函数
requests.get()
是实验性的,并且随时可能更改。
requests.get()
发起 http GET 请求。这与调用 request.do(method: "GET", ...)
完全相同。
已弃用
实验性的 requests.get
已弃用,推荐使用 requests.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 "experimental/http/requests"
response = requests.get(url: "http://example.com")
requests.peek(response: response)
发起 GET 请求并解码 JSON 响应
import "experimental/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}])
此页面是否有帮助?
感谢您的反馈!