I am trying to replace Webclient with HttpClient for my current functionality in my project. HttpClient does not give any error but does not delete index from Solr. What i am missing ? It gives me : Missing content type How i can correctly pass the content type ?
WebClient:
public static byte[] deleteIndex(string id)
{
System.Uri uri = new System.Uri(solrCoreConnection + "/update?commit=true");
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "text/xml";
return wc.UploadData(uri, "POST", Encoding.ASCII.GetBytes("<delete><id>" + id + "</id></delete>"));
}
}
HttpClient: (no errors, but doesn't delete the index)
public static async Task<HttpResponseMessage> deleteIndex(string id)
{
System.Uri uri = new System.Uri(solrCoreConnection + "/update?commit=true");
ResettableLazy<HttpClient> solrClient = new ResettableLazy<HttpClient>(SolrInstanceFactory);
solrClient.Value.DefaultRequestHeaders.Add("ContentType", "text/xml");
byte[] bDelete = Encoding.ASCII.GetBytes("<delete><id>" + id + "</id></delete>");
ByteArrayContent byteContent = new ByteArrayContent(bDelete);
HttpResponseMessage response = await solrClient.Value.PostAsync(uri.OriginalString, byteContent);
var contents = await response.Content.ReadAsStringAsync();
return response;
}
It gives me : Missing content type How i can correctly pass the content type ?
{
"responseHeader":{
"status":415,
"QTime":1},
"error":{
"metadata":[
"error-class","org.apache.solr.common.SolrException",
"root-error-class","org.apache.solr.common.SolrException"],
"msg":"Missing ContentType",
"code":415}}