Commit 8fc440da by gongyang

修改方法不正确

parent 03c3dca6
Showing with 12 additions and 25 deletions
......@@ -6,7 +6,6 @@ import (
"fmt"
"golang-asynctask/app/dao/scm_data_dao"
"io/ioutil"
"mime/multipart"
"net/http"
"runtime"
"strconv"
......@@ -245,40 +244,28 @@ func RequestUrl(url string) string {
func PostTopSearchUrl() string {
url := "https://icso.ichunt.com/search/SearchLog/aggs"
method := "POST"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
_ = writer.WriteField("start_time", strconv.FormatInt(timeStart.Unix(), 10))
_ = writer.WriteField("end_time", strconv.FormatInt(currentUnix, 10))
_ = writer.WriteField("no_rule", "1122")
_ = writer.WriteField("limit", "200")
err := writer.Close()
if err != nil {
fmt.Println(err)
return ""
}
client := &http.Client{}
req, err := http.NewRequest(method, url, payload)
// 要发送的数据
data := `{"start_time":"` + strconv.FormatInt(timeStart.Unix(), 10) + `", "end_time":"` + strconv.FormatInt(currentUnix, 10) + `", "no_rule":"1122", "limit":"200"}`
// 将数据转换为字节切片
payload := bytes.NewBufferString(data)
// 发送POST请求
resp, err := http.Post(url, "application/json", payload)
if err != nil {
fmt.Println(err)
return ""
}
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return ""
}
body, err := ioutil.ReadAll(res.Body)
defer res.Body.Close()
defer resp.Body.Close()
// 读取响应体
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
return ""
}
// 打印响应内容
return string(body)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment