[英]Get an java.io.IOException: Server returned HTTP response code: 400 for URL but can access it fine in browser
The parameter I tried passing was "Submitted_By:test2 OR Submitted_By:test". 我尝试传递的参数是“ Submitted_By:test2或Submitted_By:test”。 If I copy and paste the exact URL in the error message I can access the URL just fine.
如果我将确切的URL复制并粘贴到错误消息中,则可以正常访问该URL。 When passing a parameter such as "Submitted_By:test2" it works fine but when adding the " OR " it throws the error.
当传递诸如“ Submitted_By:test2”之类的参数时,它可以正常工作,但是在添加“ OR”时,它将引发错误。 Any ideas?
有任何想法吗?
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>)
The line 144 it refers to is the last line in the provided snippet of code. 它引用的行144是所提供的代码段中的最后一行。 The Search.getResultsBeta method:
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");
Solved the problem by encoding the query variable. 通过编码查询变量解决了该问题。
Changing my code from: 更改我的代码从:
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");
To this: 对此:
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.