我将以下内容发布到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时,失败并出现以下错误:
基础
系统.无效操作异常=
“远程服务器返回错误:
(500)内部服务器错误。“
当我在Apache日志中查看服务器时,它给出了以下原因:
输入块结尾意外
以下是完整的堆栈跟踪:
2009年9月17日上午10:13:53
组织.apache.solr.common.solrexception
日志严重:
com.ctc.wstx.exc.wstxeofe例外:
输入块结尾意外
[行,列未知源]处的标记:
[261266]在
Ctc.WSTX.S.StudioStudio.SpRunMeunTeDeOB(StudioSurviv.java:700)
在
COST.CTC.WSTX.S.StudioStudio.LoopMuleFaseFielt(流扫描仪. Java:1054)
在
COST.CTC.WSTX.S.StudioStudio.GETNExtCurFaseFielt(流扫描仪. Java:811)
在
com,cTc.WSTX.S.Basic StudioRealth.Read DeNeLeEM(Basic StudioRealth.java:3211)
在
COT.CTC.WSTX.S.Basic StudioRealth.NeXFROTER树(Basic StudioRealth.java:2832)
在
COT.CTC.WSTX.S.Basic StudioRealth.NeXT(Basic StudioRealth.java:1019)
在
Org.Apache .SoR.Halter-XMLUpDATE.ErthEththDun.PraseSuffDead(XMLUpDATE.ErtheSthordal.java:148)
在
Org.Apache .SoR.Halter-XMLUpDATE.ErthEththorer-HoalLeReStEsStand(XMLUpDATE.EdthSthordal.java:123)
在
Org.Apache .SoR.Halter-Reqththand LeBase.HANDLeReStest.(Reqththand LeBase.java:131)
在
Org.Apache .SoR.Cork.SorrCork. Excel(SoRoCor.java:1204)
在
Org.Apache .SoR.servlet .SorrDebug过滤器.Excel(SoReDaskFortual.java:303)
在
Org.Apache .SoR.servlet .SorrDebug过滤器.DOFILTER(SoReDebug过滤器.java:232)
在
orp.Apache .Calalina .CorpApple .FieldFortualStudio。
在
Opache .Calalina .Corp.Apple .FieldLoop.DoFulter(Apple)FieldStorn.java(206)
在
Org.Acache .Calalina .Cort.StaldReAPPorToCor.调用(StaldReAPPorTime.java:233)
在
Org.Acache .Calalina .Cort.Stand AdExtCort.调用(Stand AdExtCorp.java:191)
在
Org.Acache .Calalina .Corn.StaldHoistPort.Unjk(Stand AdvortVor.java:128)
在
Org.Acache .Calalina .阀门. ErrorRePortVortu.调用(ErrorRePortVortu.java:102)
在
Org.Acache .Calalina .Cort.StRealEngEnValue.No调用(StaldEngEnValv.java:109)
在
Oracy.Calalina .Cornor.CyoToAddio.Service(CyoToAddio.java:293)
在
orp.Apache .cyoOut.Htp11. Htp11ApPosial.进程(HTTP11ApPosial.java:859)
在
org.Apache .cyoop.HTTP11. HTTP11APPLANT$$HTTP11CornAccess处理程序.(HTTP11ApPrase.java:574)
在
Oracy.Tomcat .UTI.NET .Apple点.Works.Run(Apple Posith.java:1527)
在
Java.Lang.Tr.Run(线程.java:619)
请注意,solr服务器正在以下系统上运行:
Microsoft Windows Server 2003 R2
阿帕奇Tomcat 6
最后,我的问题是:
我发送的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.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);
}
}