gpt4 book ai didi

http - golang http.Get()获取不到内容,反而500错误。为什么?

转载 作者:IT王子 更新时间:2023-10-29 02:30:30 26 4
gpt4 key购买 nike

我无法获取站点的内容,它返回 500 错误。但是,如果我切换到 www.google.com.hk 或其他网站,就可以了。为什么?

下面是代码。

package main

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

func main() {
resp, err := http.Get("http://www.eqsn.gov.cn") //the browsers,IE\firefox access it is ok.
// resp, err := http.Get("http://www.google.com.hk") //It's ok.

if err != nil {
log.Fatalf("http.Get => %v", err.Error())
}
body, _ := ioutil.ReadAll(resp.Body)
fmt.Printf("\n%v\n\n", string(body))
}

最佳答案

如果 http.Get() 的执行返回错误 500(内部服务器错误),则此错误很可能来自服务器。事实上,让我们手动尝试。选项 -D- 转储 header 。

$ curl -D- http://www.eqsn.gov.cnHTTP/1.0 500 Internal Server Error
Date: Mon, 17 Jun 2013 02:01:11 GMT
Content-Type: text/html; charset=iso-8859-1
Content-Length: 538
X-Powered-By:
X-AspNet-Version:
MicrosoftOfficeWebServer:
Server:
X-Cache: MISS from CNC-JSWX-254-131.fastcdn.com
X-Cache: MISS from CT-ZJNB-152-196.fastcdn.com
Connection: close

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
[no address given] and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
</body></html>

如您所见,服务器给您一个错误 500。Go 工作得很好;它给你服务器发送的错误 500。如果您还有其他问题,请随时提出。

关于http - golang http.Get()获取不到内容,反而500错误。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17134102/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com