我正在调整最近在 .NET Standard 中启动的项目以使用 Azure Functions。我有一个 HTTP 触发器,我直接从表单发布到该触发器。只有两个字段:数字输入和文件上传。
当使用该函数而不引用任何其他库时,我无法在 HttpRequestMessage 上使用 ReadAsFormDataAsync。我收到:
System.Net.Http.UnsupportedMediaTypeException: No MediaTypeFormatter is
available to read an object of type 'FormDataCollection' from content with
media type 'multipart/form-data'.
Run Code Online (Sandbox Code Playgroud)
我可以使用 ReadAsMultipartAsync 并设法获取发布值。
但是,当我引用 .NET 标准库时,我什至无法输入该函数,因为它被完全拒绝:
System.Net.Http.UnsupportedMediaTypeException: No MediaTypeFormatter is
available to read an object of type 'HttpRequestMessage' from content with
media type 'multipart/form-data'
Run Code Online (Sandbox Code Playgroud)
我尝试创建一个全新的框架 .NET 标准库并引用它和同样的东西。
作为附加参考,我找到了这篇文章,但我似乎没有遇到同样的问题。
本来打算提交一个问题,但决定先在这里尝试一下。有任何想法吗?
编辑:当 enctype 为 application/x-www-form-urlencoded 时,也会发生这种情况。