gpt4 book ai didi

html - Solr 响应中的内容类型

转载 作者:行者123 更新时间:2023-12-04 12:47:47 25 4
gpt4 key购买 nike

我一直在学习 Solr 并遇到了一个问题。如果我像这样向 Solr 查询:

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

我得到一个包含 JSON 响应的网页。但是,网页标题没有说明 Content-Type。

我想在标题中获取 Content-Type 以便查询 Solr 的人可以使用 pretty-print 工具来清理 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>

编辑:感谢下面的答案,我把它修好了。我使用 Config 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"
}
}
}'

请注意,更改不会立即对我生效,因此您可能需要等待一分钟才能显示更改。

最佳答案

例如solrconfig.xml建议,您应该修复 Content-Type通过删除以下部分:

  <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 查看器的现代浏览器会将 JSON 显示为纯文本,因此除非您想在 IE6 之类的东西中查看数据,否则您会没事的。

通过 http://grokbase.com/t/lucene/dev/1372n9jyha/solr-content-type-for-json 发现

关于html - Solr 响应中的内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42938444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com