dsa88885555 2018-11-29 15:24
浏览 677
已采纳

http.get()返回“ 422无法处理的实体”

I have written a go programme to query issues in github repository "golang:go". The http.Get() responds with status "200 OK". I then query for issues created in last 3 months and the http.Get() returns "422 Unprocessable Entity". Below is the programme

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
", timeStr)

        str = from.Format("2006-01-02")
        timeStr = timeStr + str 
        fmt.Printf("time2 : %s
", 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) 
}   

I used this to form the query.

I am new to web programming and not able to understand where I went wrong in forming the second query.

  • 写回答

3条回答 默认 最新

  • dpmwy80068 2018-11-29 15:43
    关注

    two things that worked for me

    1) reverse the "from" and "to" in your timeStr

    2) don't use QueryEscape on the timeStr, just add it in like this

       urlStr = "https://api.github.com/search/issues" + "?q=repo:golang/go+" + timeStr
    

    Don't use an ampersand (I originally answered with this) use a plus sign or space. See https://help.github.com/articles/searching-issues-and-pull-requests/#search-by-when-an-issue-or-pull-request-was-created-or-last-updated for the syntax

    update: on further consideration the QueryEscape is a good idea! It seems coincidentally to "just work"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 经gamit解算的cors站数据再经globk网平差得到的坐标做形变分析
  • ¥15 GD32 SPI通信时我从机原样返回收到的数据怎么弄?
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题