我正在尝试使用httpClient作为八位字节流上传文件
旁注:在我的代码中,Accept和Bearer标头及其值已经存在于要通过“ await GetRestClientAsync()”获取的客户端中
我希望得到答复,但是现在我什么也没回来,应用程序停止了,我在这里做错了什么?
Ps:其他帖子,对此api的请求在我在这里使用的同一客户端上也能正常工作,因此我很可能将MultiPartFormDataContent弄乱了
protected async Task<TResponse> ExecutePostAsBinaryCustomHeadersAsync<TResponse>(Uri apiUri, Stream fileStream, string fileName ,bool returnDefaultObjectForInternalServerError = false)
{
using (var formData = new MultipartFormDataContent())
{
formData.Add(new StringContent(fileName), "x-file-name");
formData.Add(new StringContent("true"), "x-convert-document");
formData.Add(new StringContent("Agion"), "x-source");
formData.Add(new StringContent("application/octet-stream"), "Content-Type");
using (var client = await GetRestClientAsync())
{
StreamContent content = new StreamContent(fileStream);
formData.Add(content, "file", fileName);
using (var response = await client.PostAsync(apiUri, formData))
{
return await DeserializeResponseAsync<TResponse>(response, returnDefaultObjectForInternalServerError);
}
}
}
}