我想发送此休息电话...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)}
1 回答
慕哥6287543
TA贡献1831条经验 获得超10个赞
鉴于服务器不处理百分比编码,请使用基本字符串操作来构造 URI。
要解决 net/http 包对 URL 的解码和编码问题,请使用 URL.Opaque 字段指定 URI。
func searchOnMavenCentral() {
var groupId = "ch.viascom.groundwork"
var artifactId = "foxhttp"
qp := "q=g:\"" + groupId + `"+AND+a:"` + artifactId + `"` +
"&rows=20" +
"&core=gav"
req, _ := http.NewRequest("GET", "http://search.maven.org", nil)
req.URL = &url.URL{
Scheme: req.URL.Scheme,
Host: req.URL.Host,
Opaque: "/solrsearch/select?" + qp,
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatalln(err)
}
log.Println(resp.Request.URL)
log.Println(resp)
}
- 1 回答
- 0 关注
- 2966 浏览
添加回答
举报
0/150
提交
取消