按如下所示執行獲取 URLresp, err := http.Get(path)事先,我打印了或多或少像這樣變量pathhttp://localhost:8080/api/history/resources/count?startedAfter="2021-03-06T15%3A27%3A13.894415787%2B0200"當我點擊鏈接時,它確實返回并得到有效的響應。200json但是,代碼本身會失敗并打?。?lt;!doctype html><html><head><title>HTTP Status 400 – Bad Request</title>Invalid character found in the request target [/api/history/resources/count?startedAfter="2021-03-06T15%3A27%3A13.894415787%2B0200"]. The valid characters are defined in RFC 7230 and RFC 3986</p><p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</p><p><b>Exception</b></p><pre>java.lang.IllegalArgumentException: Invalid character found in the request target [/apit/history/resources/count?startedAfter="2021-03-06T15%3A27%3A13.894415787%2B0200"]. The valid characters are defined in RFC 7230 and RFC 3986 org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:491) org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:260) org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.base/java.lang.Thread.run(Thread.java:834)為什么?
1 回答
千萬里不及你
TA貢獻1784條經驗 獲得超9個贊
查詢參數中的引號似乎導致服務器出現錯誤。試試這樣的東西
apiURL := "http://localhost:8080/api/history/resources/count"
req, err := http.NewRequest("GET", apiURL, nil)
if err != nil {
log.Fatal(err)
}
apiParams := req.URL.Query()
apiParams.Add("startedAfter", "2021-03-06T15:27:13.894415787+0200")
req.URL.RawQuery = apiParams.Encode()
res, err := http.DefaultClient.Do(req)
嘗試并還原。
- 1 回答
- 0 關注
- 142 瀏覽
添加回答
舉報
0/150
提交
取消
