C# Httpclient asp.net核心卷
我对ASP.Net HttpClient POST请求有问题。 事实上,我想使用SolrCell在Solr中索引文档。我用过这样的卷发:C# Httpclient asp.net核心卷,c#,asp.net,solr,asp.net-core,apache-tika,C#,Asp.net,Solr,Asp.net Core,Apache Tika,我对ASP.Net HttpClient POST请求有问题。 事实上,我想使用SolrCell在Solr中索引文档。我用过这样的卷发: curl 'http://localhost:8983/solr/my_collection/update/extract?literal.id=doc1&commit=true' -F "myfile=@example/exampledocs/solr-word.pdf" 不幸的是,我只能将文件作为多部分文件上传(使用HttpClient)发送,这
curl 'http://localhost:8983/solr/my_collection/update/extract?literal.id=doc1&commit=true' -F "myfile=@example/exampledocs/solr-word.pdf"
不幸的是,我只能将文件作为多部分文件上传(使用HttpClient)发送,这样我需要确定文件的mime类型,虽然我这样做了,但我仍然得到了DOCX和PPTX文件的错误
这是我的密码:
var fileBytes = File.ReadAllBytes(path);
requestContent.Add(new ByteArrayContent(fileBytes), "file");
requestContent.Headers.Remove("Content-Type");
requestContent.Headers.Add("Content-Type", contentType);
var response = await client.PostAsync(defaultSolrUri, requestContent);
return response.Content;
请帮忙。我找到了解决办法!无需传递MultiPartFormData,只需将文件作为PostAsyn中的ByteArrayContent传递:
string path = "path/to/file";
var fileBytes = File.ReadAllBytes(path);
var response = await client.PostAsync(defaultSolrExtractUri, new ByteArrayContent(fileBytes));
return response.Content;
这里的
contentType
变量的值是什么?application/vnd.openxmlformats-officedocument.presentationml.presentationFile扩展名:pptx Mime类型:application/vnd.openxmlformats-officedocument.presentationml.presentation