![](/img/trans.png)
[英]server returns java.io.IOException: Server returned HTTP response code: 400 for URL
[英]Get an java.io.IOException: Server returned HTTP response code: 400 for URL but can access it fine in browser
我嘗試傳遞的參數是“ Submitted_By:test2或Submitted_By:test”。 如果我將確切的URL復制並粘貼到錯誤消息中,則可以正常訪問該URL。 當傳遞諸如“ Submitted_By:test2”之類的參數時,它可以正常工作,但是在添加“ OR”時,它將引發錯誤。 有任何想法嗎?
12:51:53,246 ERROR [stderr] (default task-1) java.io.IOException: Server returned HTTP response code: 400 for URL: http://localhost:1234/solr/STINGRA/select/?q=Submitted_By:test2 OR Submitted_By:test&fl=Submission_ID,Submitted_By,File_Name,TOT&version=2.2&start=0&rows=50&indent=on&wt=xml&callback=?&json.wrf=on_data
12:51:53,247 ERROR [stderr] (default task-1) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1839)
12:51:53,247 ERROR [stderr] (default task-1) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
12:51:53,247 ERROR [stderr] (default task-1) at java.net.URL.openStream(URL.java:1038)
12:51:53,247 ERROR [stderr] (default task-1) at webapp.Search.getResultsBeta(Search.java:144)
12:51:53,247 ERROR [stderr] (default task-1) at webapp.WebappController.searchResultsBeta(WebappController.java:87)
12:51:53,248 ERROR [stderr] (default task-1) at webapp.WebappController$$FastClassBySpringCGLIB$$b0db6f6a.invoke(<generated>)
它引用的行144是所提供的代碼段中的最后一行。 Search.getResultsBeta方法:
public static Integer[] getResultsBeta(String query) {
String inputLine;
ArrayList<Integer> subId = new ArrayList<>();
int numOfResults = 0;
try {
URL temp;
temp = new URL("http://localhost:1234/solr/STINGRA/select/?q=" + query + "&fl=Submission_ID,Submitted_By,File_Name,TOT&version=2.2&start=0&rows=50&indent=on&wt=xml&callback=?&json.wrf=on_data");
BufferedReader in;
InputStreamReader sr = new InputStreamReader(temp.openStream());
您應該使用url = url.replaceAll(" ", "%20");
空格編碼為'%20' url = url.replaceAll(" ", "%20");
通過編碼查詢變量解決了該問題。
更改我的代碼從:
URL temp;
temp = new URL("http://localhost:1234/solr/STINGRA/select/?q=" + query + "&fl=Submission_ID,Submitted_By,File_Name,TOT&version=2.2&start=0&rows=50&indent=on&wt=xml&callback=?&json.wrf=on_data");
對此:
URL temp;
query = URLEncoder.encode(query);
temp = new URL("http://localhost:1234/solr/STINGRA/select/?q=" + query + "&fl=Submission_ID,Submitted_By,File_Name,TOT&version=2.2&start=0&rows=50&indent=on&wt=xml&callback=?&json.wrf=on_data");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.