gpt4 book ai didi

lucene - Solr - 将 "Add"发布到服务器时出错

转载 作者:行者123 更新时间:2023-12-02 06:33:27 25 4
gpt4 key购买 nike

我将以下内容发布到 Solr 服务器:

<add>
<doc>
<field name="uniqueid">5453543</field>
<field name="modifieddate">2008-12-03T15:49:00Z</field>
<field name="title">My Record</field>
<field name="description">Descirption
Details
</field>
<field name="startdate">2009-01-21T15:26:05.680Z</field>
<field name="enddate">2009-01-21T15:26:05.697Z</field>
<field name="Telephone_number">11111 111 111(text phone)</field>
<field name="Telephone_number">11111 111 111</field>
<field name="Mobile_number">1111111111</field>
</doc>
</add>

我正在使用SolrNet 要发送文档,这里是代码摘录(s 是上面的 xml):

public string Post(string relativeUrl, string s) 
{
var u = new UriBuilder(serverURL);
u.Path += relativeUrl;
var request = httpWebRequestFactory.Create(u.Uri);
request.Method = HttpWebRequestMethod.POST;
request.KeepAlive = false;
if (Timeout > 0)
request.Timeout = Timeout;
request.ContentType = "text/xml; charset=utf-8";
request.ContentLength = s.Length;
request.ProtocolVersion = HttpVersion.Version10;
try
{
using (var postParams = request.GetRequestStream())
{
postParams.Write(xmlEncoding.GetBytes(s), 0, s.Length);
using (var response = request.GetResponse())
{
using (var rStream = response.GetResponseStream())
{
string r = xmlEncoding.GetString(ReadFully(rStream));
//Console.WriteLine(r);
return r;
}
}
}
}
catch (WebException e)
{
throw new SolrConnectionException(e);
}
}

当它到达 request.GetResponse 时,它​​失败并出现以下错误:

base {System.InvalidOperationException} = {"The remote server returned an error: (500) Internal Server Error."}

当我在 apache 日志中查看服务器时,它给出了以下原因:

Unexpected end of input block in end

这是完整的堆栈跟踪:

Sep 17, 2009 10:13:53 AM org.apache.solr.common.SolrException log SEVERE: com.ctc.wstx.exc.WstxEOFException: Unexpected end of input block in end tag at [row,col {unknown-source}]: [26,1266] at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOB(StreamScanner.java:700) at com.ctc.wstx.sr.StreamScanner.loadMoreFromCurrent(StreamScanner.java:1054) at com.ctc.wstx.sr.StreamScanner.getNextCharFromCurrent(StreamScanner.java:811) at com.ctc.wstx.sr.BasicStreamReader.readEndElem(BasicStreamReader.java:3211) at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2832) at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1019) at org.apache.solr.handler.XmlUpdateRequestHandler.processUpdate(XmlUpdateRequestHandler.java:148) at org.apache.solr.handler.XmlUpdateRequestHandler.handleRequestBody(XmlUpdateRequestHandler.java:123) at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:131) at org.apache.solr.core.SolrCore.execute(SolrCore.java:1204) at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:303) at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:232) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859) at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:574) at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527) at java.lang.Thread.run(Thread.java:619)

请注意 Solr 服务器正在以下系统上运行:

微软 Windows Server 2003 R2Apache Tomcat 6

最后这是我的问题:

我发送的 Xml 对我来说看起来没问题。有人知道为什么 Solr 会抛出这个异常吗?

谢谢

戴夫

编辑答案如下:

public string Post(string relativeUrl, string s) 
{
var u = new UriBuilder(serverURL);
u.Path += relativeUrl;
var request = httpWebRequestFactory.Create(u.Uri);
request.Method = HttpWebRequestMethod.POST;
request.KeepAlive = false;
if (Timeout > 0)
request.Timeout = Timeout;
request.ContentType = "text/xml; charset=utf-8";
request.ProtocolVersion = HttpVersion.Version10;
try
{
// Set the Content length after the size of the byte array has been calculated.
byte[] data = xmlEncoding.GetBytes(s);
request.ContentLength = s.Length;
using (var postParams = request.GetRequestStream())
{
postParams.Write(data, 0, data.Length);
using (var response = request.GetResponse())
{
using (var rStream = response.GetResponseStream())
{
string r = xmlEncoding.GetString(ReadFully(rStream));
//Console.WriteLine(r);
return r;
}
}
}
}
catch (WebException e)
{
throw new SolrConnectionException(e);
}
}

最佳答案

我对 .Net 或 Solr 或 Solr 的 .Net 端口不太熟悉。但是,这是我的猜测。

postParams.Write(xmlEncoding.GetBytes(s), 0, s.Length);

有两个可能的错误。

  1. 当您从 String 获取字节时,您应该指定编码。默认编码可能与您在响应的内容类型 header 中设置的 UTF8 不同。
  2. Write() 中的第三个参数可能指的是从 GetBytes() 获取的字节数组的长度。字节数组可以比字符串的长度长。

关于lucene - Solr - 将 "Add"发布到服务器时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1437721/

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