【发布时间】:2018-12-01 10:52:56
【问题描述】:
我已经编写了一个 go 代码来在我的 github 存储库中的项目中创建问题。我正在使用此处提到的参数 [https://developer.github.com/v3/issues/#create-an-issue][1]
但我收到状态为 404 的响应。下面是我的代码。
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
param := map[string]string{"title": "issue1", "body": "aassddrff", "assignee": "vigneshkm"}
query, _ := json.Marshal(param)
queryUrl := "https://api.github.com/repos/vigneshkm/first_repo/issues"
fmt.Println("query:", string(query))
resp, err := http.Post(queryUrl, "application/json", bytes.NewBuffer(query))
fmt.Println("query_status : ", resp.StatusCode, "err : ", err)
resp.Body.Close()
}
我是网络编程的初学者,我无法理解我在这段代码中的错误。请帮助我:)
【问题讨论】:
-
响应正文是什么?
-
一些 API 响应按照他们自己的约定,也可以在这里。如果我是你,会检查 cookie 并可能重定向到该 url
-
你的 API 说
Not found问题,即使我用邮递员检查过,首先检查你的 API,它是否真的存在? -
@Peter 我试图读取正文如下 "newBuf := bytes.NewBuffer(buf) ; num, ret := newBuf.ReadFrom(json.NewDecoder(resp.Body).Buffered()) ; fmt.Println("string:", newBuf.String())" 我看到输出为零。你的意思是一样的还是别的什么??
-
您会收到 HTTP 404,因为这是一个需要身份验证的 POST 请求。见:developer.github.com/v3/#authentication
标签: http go http-post github-api