我在使用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)
}
fmt.Print(string(body))
}