我想发送此休息电话...
GET http://search.maven.org/solrsearch/select?q=g:"ch.viascom.groundwork"+AND+a:"foxhttp"&rows=100&core=gav
...但不能,因为它被编码为
http://search.maven.org/solrsearch/select?core=gav&q=g%3A%22ch.viascom.groundwork%22%2BAND%2Ba%3A%22foxhttp%22&rows=20
这是我的 go 函数:
func searchOnMavenCentral() {
var groupId = "ch.viascom.groundwork"
var artifactId = "foxhttp"
params := url.Values{}
params.Add("q", `g:"` + groupId + `"+AND+a:"` + artifactId + `"`)
params.Add("rows", "20")
params.Add("core", "gav")
resp, err := http.Get("http://search.maven.org/solrsearch/select?" + params.Encode())
if err != nil {
log.Fatalln(err)
}
log.Println(resp.Request.URL)
log.Println(resp)
}
我怎么解决这个问题?提前感谢您的帮助!
更新状态
在您的帮助下,我成功创建了所需的 URL,但我现在面临以下新问题:
&{400 Bad Request 400 HTTP/1.1 1 1 map[Connection:[keep-alive] Date:[Mon, 05 Aug 2019 23:56:45 GMT] Server:[nginx/1.14.1]] 0xc00011a080 -1 [chunked] false false map[] 0xc0000d4000 <nil>}
这是更新后的代码:
func searchOnMavenCentral() {
var groupId = "ch.viascom.groundwork"
var artifactId = "foxhttp"
qp := "q=g:\"" + groupId + `"+AND+a:"` + artifactId + `"` +
"&rows=20" +
"&core=gav"
u := &url.URL{
Scheme: "http",
Host: "search.maven.org",
Path: "/solrsearch/select",
RawQuery: qp,
}
resp, err := http.Get (u.String())
if err != nil {
log.Fatalln(err)
}
log.Println(resp.Request.URL)
log.Println(resp)
}
慕哥6287543
相关分类