2017-03-21 25 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就好像它是純文本,所以除非你想看到的:

回答

相關問題