Solr 7.5 Expected mime type application/json but got text/plain.
程序员文章站
2022-04-03 16:03:46
...
SolrJ版本7.5,Solr版本7.5。查询测试代码如下:
执行抛出异常信息:
org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://127.0.0.1:8983/solr/xxxxxx: Expected mime type application/json but got text/plain
经过一番苦苦搜索,原因居然出在 solr-7.5.0/server/solr/${core}/conf/solrconfig.xml
该配置文件中有如下配置:
各位请注意看注释里面的那段话!!!
将text/plain 修改为 application/json 运行一切正常。
SolrClient solr = new HttpSolrClient.Builder(solrUrl).build(); SolrQuery query=new SolrQuery(); query.set("q","title:"+queryStr); query.set("wt","json"); try { QueryResponse solrResponse=solr.query(query ); SolrDocumentList results = solrResponse.getResults(); System.out.println(results.toString()); } catch (SolrServerException e) { e.printStackTrace(); }
执行抛出异常信息:
org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://127.0.0.1:8983/solr/xxxxxx: Expected mime type application/json but got text/plain
经过一番苦苦搜索,原因居然出在 solr-7.5.0/server/solr/${core}/conf/solrconfig.xml
该配置文件中有如下配置:
<queryResponseWriter name="json" class="solr.JSONResponseWriter"> <!-- For the purposes of the tutorial, JSON responses are written as plain text so that they are easy to read in *any* browser. If you expect a MIME type of "application/json" just remove this override. --> <str name="content-type">text/plain; charset=UTF-8</str> </queryResponseWriter>
各位请注意看注释里面的那段话!!!
将text/plain 修改为 application/json 运行一切正常。
上一篇: Java类加载器深入解析(二)