小编nem*_*emo的帖子

Golang HTTP 并发请求 POST EOF

我在 Go 中运行一个小客户端。目前我们收到了许多误报,这似乎归结为client.Do()num>=1000.

这是我的代码的本质:

func DoCreate(js string, cli *http.Client) {

    url2 := "http://xvz.myserver.com:9000/path/create"

    postBytesReader := bytes.NewReader([]byte(js))
    request, _ := http.NewRequest("POST", url2, postBytesReader)

    resp, err := cli.Do(request)
    if err != nil {
        fmt.Println(err) // Post http://xvz.myserver.com:9000/path/create: EOF 
        return
    }
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(body))

    defer resp.Body.Close()
}

func main() {
    client := &http.Client{
        CheckRedirect: nil,
    }

    for i := 0; i < num; i++ {
        var pq CreateReqInfo
        pq.Uid = strconv.Itoa(bid + i)
        petstr, _ := json.Marshal(pq) …
Run Code Online (Sandbox Code Playgroud)

http go web

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

go ×1

http ×1

web ×1