2017-03-21 151 views
1

我一直在学习Solr并遇到问题。如果我这样查询Solr:Solr响应内容类型

curl "http://localhost:8983/solr/myCollection/select?q=*:*&wt=json&rows=0" 

我得到一个有JSON响应的网页。但是,网页标题中没有提及Content-Type。

我想在头文件中获取Content-Type,以便查询Solr的人可以使用漂亮的打印工具来清理Solr响应,并使其更加可读,而无需提供“indent = on”选项时间。

任何帮助?

感谢

<html> 
    <head> 
    <link rel="alternate stylesheet" type="text/css" 
    href="resource://gre-resources/plaintext.css" 
    title="Wrap Long Lines"> 
    <style type="text/css"></style> 
    </head> 
    <body> 
    <pre>{"responseHeader":{"status":0,"QTime":0,"params": 
     {"q":"*:*","rows":"0","wt":"json"}},"response": 
     {"numFound":27394430,"start":0,"docs":[]}} 
    </pre> 
    </body> 
</html> 

编辑:多亏了下面的答案,我得到它固定。我使用配置API所做的更改:

curl http://localhost:8983/solr/collectionName/config 
    -H 'Content-Type:application/json' -d '{ 
    "update-queryresponsewriter" : { 
    "name":"json", 
    "class":"solr.JSONResponseWriter", 
    "defaults": { 
     "name":"application/json; charset=UTF-8" 
    } 
    } 
}' 

正如一个音符,变化并没有立即生效对我来说,所以你可能需要等待一分钟更改露面。

没有JSON观众
<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> 

现代浏览器将显示JSON就好像它是纯文本,所以除非你想看到的:

回答

相关问题