Httpclient asp.net核心卷曲等效
问题描述:
我有一个ASP.Net HttpClient POST请求的问题。 事实上,我想使用SolrCell在Solr中索引文档。我用卷发这样的:Httpclient asp.net核心卷曲等效
curl 'http://localhost:8983/solr/my_collection/update/extract?literal.id=doc1&commit=true' -F "[email protected]/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,所有你需要做的是将文件传递的ByteArrayContent在PostAsyn:
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.presentation –
文件扩展名:pptx Mime-Type:application/vnd.openxmlformats-officedocument.presentationml.presentation –