gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 00:00:28 27 4
gpt4 key购买 nike

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

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

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

我收到“无法在浏览器控制台中加载资源:服务器响应状态为 415(不支持的媒体类型)”错误。

在 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, 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)"}

最佳答案

创建 JSPlumb 实例时添加 header :

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

关于javascript - 如何在jsPlumb保存功能中设置Mime类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40725592/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com