Commit 8fc440da by gongyang

修改方法不正确

parent 03c3dca6
Showing with 12 additions and 25 deletions
...@@ -6,7 +6,6 @@ import ( ...@@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"golang-asynctask/app/dao/scm_data_dao" "golang-asynctask/app/dao/scm_data_dao"
"io/ioutil" "io/ioutil"
"mime/multipart"
"net/http" "net/http"
"runtime" "runtime"
"strconv" "strconv"
...@@ -245,40 +244,28 @@ func RequestUrl(url string) string { ...@@ -245,40 +244,28 @@ func RequestUrl(url string) string {
func PostTopSearchUrl() string { func PostTopSearchUrl() string {
url := "https://icso.ichunt.com/search/SearchLog/aggs" 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 { if err != nil {
fmt.Println(err) fmt.Println(err)
return "" return ""
} }
req.Header.Set("Content-Type", writer.FormDataContentType()) defer resp.Body.Close()
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return ""
}
body, err := ioutil.ReadAll(res.Body)
defer res.Body.Close()
// 读取响应体
body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return "" return ""
} }
// 打印响应内容
return string(body) 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