アプリケーションの開発に ASPNET Boilerplate フレームワークを使用していますが、これは WebAPI 固有の問題であると確信しています。次のアプリケーション層関数に基づいて構築された動的 WebAPI 関数を使用しています。
私の Angular アプリでは、次のコードを使用してデータを動的 API に POST し、最終的にアプリケーション層関数に渡します。
var formDataObject = new FormData();
formDataObject.append('avatar', vm.group.avatar);
formDataObject.append('name', vm.group.name);
formDataObject.append('description', vm.group.description);
$.ajax({
url: abp.appPath + 'api/services/app/group/CreateGroup',
processData: false,
//contentType: false,
type: 'POST',
data: formDataObject
});
Chrome コンソールに次のエラーが表示されます。
{"message":"The request entity's media type 'application/x-www-form-urlencoded' is not supported for this resource.","exceptionMessage":"No MediaTypeFormatter is available to read an object of type 'InputGroup' from content with media type 'application/x-www-form-urlencoded'.","exceptionType":"System.Net.Http.UnsupportedMediaTypeException","stackTrace":" at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)"}
次の解決策を試しましたが、成功しませんでした。
- パラメーターの型として FormDataCollection を使用します。
- ファイル (アバター) オブジェクトなしで投稿します。失敗した。
- application/formdata タイプで投稿します。失敗した。
インターネットで見たすべての解決策がうまくいきません。