我试图在solr中调用数据导入处理程序将sql中的记录导入到solr集合中,我收到了ui从fiddler发送的请求,并且我在我的使用中使用相同的请求c#应用程序,但请求不导入数据。任何人都可以帮我搞定这个吗?
public class SolrRequest
{
public string SendPostRequest(string requestType, string dataToPost, string requestInfo, string pathOfRequest)
{
LocalhostSet.LocalhostSet solrlocalhost = new LocalhostSet.LocalhostSet();
string hasSuccess = "";
string localhostSet = "";
localhostSet = solrlocalhost.setLocalHost(localhostSet);
string URI = "http://localhost:8999/solr/new_core/dataimport" ;
string myParameters = "full-import&clean=true&commit=true&wt=json&indent=true&entity=holidays&rows=10000000&verbose=false&optimize=false&debug=false";
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HtmlResult = wc.UploadString(URI, myParameters);
}
try
{
Console.WriteLine(requestInfo);
var request = HttpWebRequest.Create(localhostSet);
request.Method = requestType;
request.ContentType = "application/x-www-form-urlencoded";
if (requestType.Equals("PUT") | requestType.Equals("POST"))
{
using (var writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(dataToPost);
}
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
hasSuccess = "Request Successful";
string status = response.StatusDescription.ToString();
if (requestType.Equals("GET"))
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string tmp = reader.ReadToEnd();
}
}
catch (WebException webex)
{
WebResponse errResp = webex.Response;
using (Stream respStream = errResp.GetResponseStream())
{
StreamReader reader = new StreamReader(respStream);
string text = reader.ReadToEnd();
}
hasSuccess = "Request Unsuccessful";
}
Console.WriteLine(hasSuccess);
return hasSuccess;
}
答案 0 :(得分:0)
网址错误,网址应引用此案例中的集合“new_core”
http://localhost:8999/solr/new_core/dataimport?command=full-import