can't get the content by golang http.Get()? why?

I can’t get a site’s content. it returns the 500 error, but swiths to www.google.com.hk or other sites. It’s OK. why?
The following is the code.

     package main
    import (
        "fmt"
        "log"
        "net/http"
        "io/ioutil"
    )
    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))
    }
  

Comments 1

  • 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.

发表评论

电子邮件地址不会被公开。 必填项已用*标注