requests.post() 函数
requests.post() 发起一个 http POST 请求。这与调用 request.do(method: "POST", ...) 是相同的。
函数类型签名
(
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}
有关更多信息,请参见 Function type signatures。
参数
网址
(必填) 请求的URL。这里不应该包括任何查询参数。
参数
要添加到URL作为查询参数的一组键值对。 查询参数将被URL编码。 与一个键相关的所有值将附加到查询中。
头部信息
请求中要包含的键值对集合。
主体
要随请求发送的数据。
配置
控制请求执行方式的选项集。
示例
使用 JSON 主体进行 POST 请求并解码 JSON 响应
import "http/requests"
import ejson "experimental/json"
import "json"
import "array"
response =
requests.post(
url: "https://goolnk.com/api/v1/shorten",
body: json.encode(v: {url: "http://www.influxdata.com"}),
headers: ["Content-Type": "application/json"],
)
data = ejson.parse(data: response.body)
array.from(rows: [data])
使用查询参数进行POST请求
import "http/requests"
response =
requests.post(url: "http://example.com", params: ["start": ["100"], "interval": ["1h", "1d"]])
// Full URL: http://example.com?start=100&interval=1h&interval=1d
requests.peek(response: response)