I'm trying to get the RestSharp (v107) equivalent of the following cURL command:
curl --insecure -H "Content-Type: application/x-ndjson" -XPOST -u user:password https://localhost:9200/products/_bulk --data-binary "@pathtofile/products-bulk.json"
The file: products-bulk.json, contains many json objects separated by endlines (ndjson format).
Here is my attempt at doing this:
string base_url = "https://localhost:9200";
// disabling SSL certificate (for my specific use, you could ignore that)
var options = new RestClientOptions(base_url)
{
RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true
};
var client = new RestClient(options);
string username = "user";
string password = "password";
client.Authenticator = new HttpBasicAuthenticator(username, password);
var request = new RestRequest() ;
request.Method = Method.Post;
request.Resource = "products/_bulk";
request.RequestFormat = DataFormat.Binary; // sending via --data-binary format
request.AddHeader("Content-Type", "application/ndjson");
string path = @"pathtofile\products-bulk.json";
request.AddFile("file",path);
var response = client.Execute(request);
However, ndjson seems to be not a supported format and throws the following error:
{"error":"Content-Type header [application/ndjson; boundary="03713f22-b45c-40ed-a9f6-50949a99a017"] is not supported","status":406}
Some online source said to use json instead of ndjson in request.AddHeader and add an iso-8859-1 encoding through RestClientOptions as a workaround. But that didn't work for me and throws me a different error. (At the moment, I'm unable to pull the source. I'll update it if I find it)
Any help is appreciated. I'm fairly new to programming. Apologies for any incorrect terminologies used.