Solr 7.5 Expected mime type application/json but got text/plain._JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Solr 7.5 Expected mime type application/json but got text/plain.

Solr 7.5 Expected mime type application/json but got text/plain.

 2018/10/26 18:18:39  mayang_lang  程序员俱乐部  我要评论(0)
  • 摘要:SolrJ版本7.5,Solr版本7.5。查询测试代码如下:HttpSolrClientsolr=newHttpSolrClient.Builder(solrUrl).build();solr.setParser(newDelegationTokenResponse.JsonMapResponseParser());SolrQueryquery=newSolrQuery();query.set("q","title:"+queryStr);query.set("wt","json");try
  • 标签:JSON APP JS
SolrJ版本7.5,Solr版本7.5。查询测试代码如下:
class="java">
HttpSolrClient solr = new HttpSolrClient.Builder(solrUrl).build();
        
solr.setParser(new DelegationTokenResponse.JsonMapResponseParser());
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 运行一切正常。
上一篇: C++开发EOS基础指南(入门教程):模版 下一篇: 没有下一篇了!
发表评论
用户名: 匿名