发送请求:
http://localhost:8080/solr/update/?stream.body=
<delete><id>id值</id></delete>&stream.contentType=text/xml;charset=utf-8&commit=true
发送请求:
http://localhost:8080/solr/update/?stream.body=
<add><doc><field name=“id”>id值</field></doc></add>&stream.contentType=text/xml;charset=utf-8&commit=true
删除全部索引
http://localhost:8080/solr/book/admin/update/?stream.body=<delete><query>*:*</query></delete>&stream.contentType=text/xml;charset=utf-8&commit=true
获取solr Core列表
http://localhost:8080/solr/admin/cores?actin=status&wt=json
public bool AddIndexPost(StringBuilder sb)
{
string resultXml = string.Empty;
Stream outStram = null;
Stream instream = null;
SteamReader sr = null;
HttpWebResponse response = null;
HttpWebRequest request = null;
Encoding encoding = Encoding.GetEncoding("UTF-8");
string url = string.Format("http//127.0.0.1/solr/Core/update?");
string strData = sb.ToString();
strData = @"stream.body="+strData;
strData +=@"&stream.contentType=text/xml;charset=utf-8&commit=true";
byte[] data = encoding.GetBytes(strData);
try
{
request = WebRequest.Create(url) as HttpWebRequest;
request.Proxy = null;
CookieContainer cookie = new CookieContainer();
request.AllowAutoRedirect = true;
request.Method = "POST";
request.ContentType = "text/text";
request.ContentType = "application/x-www-form-urlencoded;chartset=UTF-8";
outStream = request.GetRequestStream();
outStream.Write(data,0,data.Length);
outStream.Close();
response = request.GetResponse as HttpWebResponse;
instream = response.GetResponseStream();
sr = new StreamReader(instream,encoding);
}
catch(Exception ex)
{
}
索引内容包含html时内容需要进行html和url编码