Asp.net mvc HttpContent.ReadAsStringAsync在字符集被引号包围时抛出

Asp.net mvc HttpContent.ReadAsStringAsync在字符集被引号包围时抛出,asp.net-mvc,unity3d,asp.net-web-api,file-upload,asp.net-web-api2,Asp.net Mvc,Unity3d,Asp.net Web Api,File Upload,Asp.net Web Api2,我试图将包含任意二进制数据的文件作为多部分/表单数据发布到WebAPI 2控制器 尝试使用以下命令读取文件时: var provider = new MultipartFormDataStreamProvider(uploadDirectoryPath); await Request.Content.ReadAsMultipartAsync(provider); 我得到: System.InvalidOperationException: The character set provided

我试图将包含任意二进制数据的文件作为多部分/表单数据发布到WebAPI 2控制器

尝试使用以下命令读取文件时:

var provider = new MultipartFormDataStreamProvider(uploadDirectoryPath);

await Request.Content.ReadAsMultipartAsync(provider);
我得到:

System.InvalidOperationException: The character set provided in ContentType is invalid. 
Cannot read content as string using an invalid character set. 
---> System.ArgumentException: '"utf-8"' is not a supported encoding name. 
For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
Parameter name: name
据我所知,问题在于utf-8的引号,这是内部使用的
HttpContent.ReadAsStringAsync()
中的错误

请求是从Unity3D应用程序发送的,我无法更改请求正文中的字符集

下面是我在Unity3D脚本中用于创建POST请求的代码

WWW chunkFile = new WWW("file:///" + Path.Combine(tempZipFolderPath, chunkFilenames[j]));

yield return chunkFile;

if (chunkFile.error != null)
    throw new Exception(string.Format("{0} error opening file {1}", chunkFile.error, chunkFilenames[j]));

//BUGFIX: Not using IMultipartFormSection because of https://fogbugz.unity3d.com/default.asp?826626_htlchp13nh8th2to

var form = new WWWForm();

form.AddField("chunkNumber", chunkNumber);
form.AddField("totalChunks", totalChunks);
form.AddField("identifier", tempZipFileName);
form.AddBinaryData("filename", chunkFile.bytes, chunkFilenames[j]);

var scanUploadPostRequest = UnityWebRequest.Post(WebApiScanUploadUrl, form);

yield return scanUploadPostRequest.Send();

//BUGBUG: charset UTF-8 wrapped in quotes causes error

有解决方法吗?

也许你也应该在Unity3D端发布你使用的代码…@Programmer我已经在问题中添加了相关的Unity3D代码。这里没有发现任何错误。我注意到您在服务器端使用了multipart,为什么不在客户端使用相同的东西呢。这可以通过
UnityWebRequest Post(字符串uri,列表multipartFormSections)
函数重载来完成。@Programmer因为这个bug:就像我碰到了所有存在的bug一样。在任何情况下,form.AddBinaryData都会将其转换为多部分。您是否尝试过像
form.headers[“Content Type”]=“utf-8”这样的操作?也许你也应该在Unity3D端发布你使用的代码…@Programmer我已经在问题中添加了相关的Unity3D代码。这里没有发现任何错误。我注意到您在服务器端使用了multipart,为什么不在客户端使用相同的东西呢。这可以通过
UnityWebRequest Post(字符串uri,列表multipartFormSections)
函数重载来完成。@Programmer因为这个bug:就像我碰到了所有存在的bug一样。在任何情况下,form.AddBinaryData都会将其转换为多部分。您是否尝试过像
form.headers[“Content Type”]=“utf-8”这样的操作