我有一个函数,我必须将数据以 json 格式发布到 url。当我发送数据时,它会以 json 格式给出响应。但它会向我展示:-代码给出的输出&{200 OK 200 HTTP/1.1 1 1 map[Content-Type:[application/json] X-Request-Id:[CgiFzq669pAYzRABGBAiCQiRtaznvJffAg] Keep-Alive:[timeout=60] Vary:[Accept-Encoding] X-Content-Type-Options:[nosniff] X-Download-Options:[noopen] X-Permitted-Cross-Domain-Policies:[none] Strict-Transport-Security:[max-age=631152000] X-Frame-Options:[DENY] X-Xss-Protection:[1; mode=block] Date:[Tue, 11 Dec 2018 09:35:22 GMT] Access-Control-Allow-Headers:[Content-Type, Authorization, Accept] Access-Control-Allow-Origin:[*] Access-Control-Expose-Headers:[Link]] 0xc420442080 -1 [] false true map[] 0xc42023e100 0xc4200e0d10}代码是:-func Token(c *gin.Context) { code := c.Query("code") responseToken :=TokenResponse{} token := models.PostToken{ ClientID: "appllication Id", ClientSecret: "applicationSecreteId", Code: "code", RedirectUri: c.Request.Host + c.Request.URL.RequestURI(), } bindData, err := json.Marshal(token) if err != nil { panic(err) } var jsonStr = []byte(string(bindData)) url :="https://connect.squareup.com/oauth2/token" req, err := http.Post(url, "application/json", bytes.NewBuffer(jsonStr)) fmt.Println(req, err)}type TokenResponse struct { Token string `json:"access_token"` Type string `json:"token_type"` ExpiresAt string `json:"expires_at"` MerchantId string `json:"merchant_id"`}预期输出:-{ "access_token": "token", "token_type": "bearer", "expires_at": "2019-01-10T08:20:59Z", "merchant_id": "id"}但是当我在邮递员中点击“ https://connect.squareup.com/oauth2/token ” url 时它会给我 json 但在 golang 代码中它不会显示任何 json 它将返回上述数据。谁能告诉我如何从上面的响应中获取 json 数据?
2 回答
- 2 回答
- 0 关注
- 120 浏览
添加回答
举报
0/150
提交
取消