如何在jsPlumb保存功能中设置Mime类型

How to set Mime type in jsPlumb save function

我正在尝试在 jsPlumb 中保存流程图(我使用的是 jsPlumb 工具包版本)。我的保存功能如下所示:

 jsPlumb.on(controls, "tap", function () {
        toolkit.save({
            url: "http://localhost:51987/api/Index/Save",
        });
    });

我的问题是我不知道如何在 jsPlumb 保存功能中将 请求 header 设置为 application/json

我收到 "Failed to load resource in the browser console: the server responded with a status of 415 (Unsupported Media Type)" 错误。

正在 Fiddler 中检查请求:

HTTP/1.1 415 Unsupported Media Type Cache-Control: no-cache Pragma: no-cache Content-Type: application/json; charset=utf-8 Expires: -1 Server: Microsoft-IIS/10.0 X-AspNet-Version: 4.0.30319 X-SourceFiles: =?UTF-8?B?QzpccHJvamVjdHNcc3Bpa2VzXHBsdW1wLXNwaWtlXGpzUGx1bWJBUElcanNQbHVtYkFQSVxhcGlcSW5kZXhcU2F2ZQ==?= X-Powered-By: ASP.NET Date: Mon, 21 Nov 2016 16:33:54 GMT Content-Length: 910

{"Message":"The request entity's media type 'text/plain' is not supported for this resource.","ExceptionMessage":"No MediaTypeFormatter is available to read an object of type 'JsPlumbViewModel' from content with media type 'text/plain'.","ExceptionType":"System.Net.Http.UnsupportedMediaTypeException","StackTrace":" at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable1 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)"}

创建 JSPlumb 实例时添加 headers:

var toolkit = jsPlumbToolkit.newInstance({
  saveUrl:"http://sava-data.com",
  saveHeaders:{
    "Content-Type":"application/json"
  }
});