有两个问题。第一个是应用程序使用请求作为响应。 执行请求以获得响应。

resp.StatusCode + http.StatusText(resp.StatusCode)resp.StatusCodeinthttp.StatusText(resp.StatusCode)string
r := resp.Status
r := fmt.Sprintf("%d %s", resp.StatusCode, http.StatusText(resp.StatusCode))

这是代码:

func StatusCode(PAGE string, AUTH string) (r string) {

    // Setup the request.

    req, err := http.NewRequest("GET", PAGE, nil)

    if err != nil {

        log.Fatal(err)

    }

    req.Header.Set("Authorization", AUTH)


    // Execute the request.

    resp, err := http.DefaultClient.Do(req)

    if err != nil {

        return err.Error()

    }

    

    // Close response body as required.

    defer resp.Body.Close()


    fmt.Println("HTTP Response Status:", resp.StatusCode, http.StatusText(resp.StatusCode))


    return resp.Status

    // or fmt.Sprintf("%d %s", resp.StatusCode, http.StatusText(resp.StatusCode))

}