dongshaoxiong0012 2013-06-16 14:01
浏览 283

无法通过golang http.Get()获取内容,而是出现500错误。 为什么?

I can't get a site's content, it returns the 500 error. But if I switch to www.google.com.hk or other sites, it's OK. Why?

The following is the code.

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("
%v

", string(body))
}
  • 写回答

1条回答 默认 最新

  • dth20986 2013-06-16 18:20
    关注

    If an execution of http.Get() returns an error 500 (internal server error), it is pretty likely that this error comes from the server. In fact, let's try manually. The option -D- dumps the headers.

    $ 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>
    

    As you can see, the server gives you an error 500. Go works completely fine; it gives you the error 500 the server sends. If you have further questions, feel free to ask.

    评论

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题