libcurl.NET
libcurl.NET copied to clipboard
missing content stream with post
Hi,
I'm trying to send JSON docs to SOLR with this package, but somehow I can't make it work. Here is my code:
string SOLRInsert = "http://192.168.x.x:8985/solr/test/update";
byte[] dataBytes = Encoding.ASCII.GetBytes("{\"add\":{\"commitWithin\":10000, \"doc\":" + json.ToString() + "}}");
Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
Easy easy = new Easy();
Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);
easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
easy.SetOpt(CURLoption.CURLOPT_POST, true);
easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, "Content-Type:application/json");
easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS, dataBytes);
//easy.SetOpt(CURLoption.CURLOPT_POSTFIELDSIZE, dataBytes.Length);
easy.SetOpt(CURLoption.CURLOPT_URL, SOLRInsert);
easy.Perform();
easy.Dispose();
Curl.GlobalCleanup();
the write function:
public static Int32 OnWriteData(Byte[] buf, Int32 size, Int32 nmemb, Object extraData) { Console.Write(System.Text.Encoding.UTF8.GetString(buf)); return size * nmemb; }
The SOLR gives the following error message
missing content stream
If someone could point at my problem, I would be most grateful.