用go语言实现实现向 http://192.168.13.11:7090/hy/saas/hy/patrol/api/bis_api_1666590273934地址post消息{ "_page": { "size": 100, "from": 0 }, "actual_patrol_time": "2022-09-27 12:18:33", "patrol_point_id": "1570590222721359872", "task_id": "1574569146639851520", "task_type": 1 }
时间: 2023-05-26 16:01:35 浏览: 72
A:
可以使用 Go 语言的标准库中的 net/http 包来实现 POST 请求。具体实现代码如下:
```go
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func main() {
url := "http://192.168.13.11:7090/hy/saas/hy/patrol/api/bis_api_1666590273934"
data := map[string]interface{}{
"_page": map[string]int{
"size": 100,
"from": 0,
},
"actual_patrol_time": "2022-09-27 12:18:33",
"patrol_point_id": "1570590222721359872",
"task_id": "1574569146639851520",
"task_type": 1,
}
requestBody, err := json.Marshal(data)
if err != nil {
panic(err)
}
request, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
if err != nil {
panic(err)
}
request.Header.Set("Content-Type", "application/json")
client := http.Client{}
response, err := client.Do(request)
if err != nil {
panic(err)
}
defer response.Body.Close()
}
```
代码中首先构造了一个 HTTP POST 请求,将要发送的数据编码为 JSON 格式,并设置请求头的 Content-Type 为 application/json。然后使用 http.Client 发送请求,并读取返回的响应。
阅读全文