小编pit*_*itw的帖子

Golang Http Get请求很慢

我在 Golang 中的一个简单的 HTTP Get 请求有一个非常奇怪的问题。

Golang 中对https://www.alltron.ch/json/searchSuggestion?searchTerm=notebook 的每个请求大约需要 6-8 秒(!)

如果在Chrome、Postman 或 Powershell 中触发了相同的请求则只需不到一秒钟。

有人知道为什么会发生这种情况吗?

我的代码:

package main

import (
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
)

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

    req, _ := http.NewRequest("GET", "https://www.alltron.ch/json/searchSuggestion?searchTerm=notebook", nil)

    response, err := client.Do(req)
    if err != nil && response == nil {
        log.Fatalf("Error on request. %v", err)
    }
    defer response.Body.Close()

    body, err := ioutil.ReadAll(response.Body)
    if err != nil {
        log.Fatalf("Couldn't get response body. %v", err) …
Run Code Online (Sandbox Code Playgroud)

performance get http request go

5
推荐指数
2
解决办法
2648
查看次数

标签 统计

get ×1

go ×1

http ×1

performance ×1

request ×1