我编写了一个 go 程序来查询 github 存储库“golang:go”中的问题。http.Get() 以状态“200 OK”响应。然后我查询最近 3 个月内创建的问题,http.Get() 返回“422 Unprocessable Entity”。下面是程序
import(
"fmt"
"time"
"net/http"
"net/url"
)
func main() {
var ret error
var str string
q:=url.QueryEscape("repo:golang/go")
fmt.Println("q:", q)
urlStr := "https://api.github.com/search/issues" +"?q=" + q
fmt.Println("urlStr:", urlStr)
resp, ret:= http.Get(urlStr)
fmt.Println("ret :", ret, "resp.status :", resp.Status)
timeStr := "created:"
to := time.Now()
from := to.AddDate(0, -3, 0)
str = to.Format("2006-01-02")
timeStr = timeStr + str + ".."
fmt.Printf("time1 : %s\n", timeStr)
str = from.Format("2006-01-02")
timeStr = timeStr + str
fmt.Printf("time2 : %s\n", timeStr)
q=url.QueryEscape("repo:golang/go" + timeStr)
fmt.Println("q:", q)
urlStr = "https://api.github.com/search/issues" +"?q=" + q
fmt.Println("urlStr:", urlStr)
resp, ret = http.Get(urlStr)
fmt.Println("ret :", ret, "resp.status :", resp.Status)
}
我用它来形成查询。
我是网络编程的新手,无法理解我在形成第二个查询时出错的地方。
小唯快跑啊
呼唤远方
慕少森
相关分类