我尝试传递的参数是“Submitted_By:test2 OR 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());
答案 0 :(得分:0)
您应该使用url = url.replaceAll(" ", "%20");
答案 1 :(得分:0)
通过编码查询变量来解决问题。
更改我的代码:
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");