亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Go 向本地主機服務器發出 GET http 請求時出現空響應

使用 Go 向本地主機服務器發出 GET http 請求時出現空響應

Go
千萬里不及你 2021-08-30 15:16:45
我的本地主機服務器正在運行,它只是 docker 中的容器進程。我正在嘗試實現 Go CLIENT 來構建用于創建、列出、更新、刪除功能的 REST api。當我嘗試點擊 URL 時,程序成功退出但給我一個空響應。我進一步觀察到,響應類型被“分塊”,內容長度為 -1。我是 Go 的新手,并試圖找出可能的原因是什么,或者任何人都可以為這個問題提供解決方案。這是我的代碼 - { package mainimport (    "encoding/json"    "fmt"    "io/ioutil"    "net/http")type Payload struct {    Stuff Data}type Data struct {    Id              string    Links           Links_container    Actions         Actions_container    AccountID       string    AgentID         string    AllocationState string    Compute         string    Created         string}type Links_container map[string]stringtype Actions_container map[string]stringfunc main() {    url := "http://localhost:8080/v1/containers"    res, err := http.Get(url)    if err != nil {        fmt.Println(err)    }    defer res.Body.Close()    body, err := ioutil.ReadAll(res.Body)    if err != nil {        fmt.Println(err)    }    var p Payload    err = json.Unmarshal(body, &p)    if err != nil {        panic(err)    }    fmt.Println(p.Stuff.AccountID, "\n", p.Stuff.Actions, "\n",        p.Stuff.AgentID, "\n", p.Stuff.AllocationState, "\n", p.Stuff.Compute,        "\n", p.Stuff.Created, "\n", p.Stuff.Id, "\n", p.Stuff.Links)}}
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 358 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號