.Net Core API 和 PHP/JS 客户端应用程序(Syncfusion 字处理器)

对于我的 PHP 应用程序,我需要使用Syncfusion Javascript Word Processor。为了使用默认文本对其进行实例化,Syncfusion 要求将此文本格式化为 SFDT,一种 JSON。


//SFDT Example

"sections": [

    {

        "blocks": [

            {

                "inlines": [

                    {

                        "characterFormat": {

                            "bold": true,

                            "italic": true

                         },

                         "text": "Hello World"

                     }

                 ]

             }

         ],

         "headersFooters": {

         }

     }

 ]

使用 .NET Core 包Syncfusion.EJ2.WordEditor.AspNet.Core,我可以将 doc(x) 文件转换为 sfdt 格式。因此,我使用 Visual Studio 2017 For Mac 使用此包创建了一个新的 .NET Core Web Api 应用程序。


using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Threading.Tasks;

using Microsoft.AspNetCore.Http;

using Microsoft.AspNetCore.Mvc;

using Syncfusion.EJ2.DocumentEditor;


namespace SyncfusionConverter.Controllers

{

    [Route("api/[controller]")]

    public class SyncfusionController : Controller

    {


        [AcceptVerbs("Post")]

        public string Import(IFormCollection data)

        {

            if (data.Files.Count == 0)

                return null;

            Stream stream = new MemoryStream();

            IFormFile file = data.Files[0];

            int index = file.FileName.LastIndexOf('.');

            string type = index > -1 && index < file.FileName.Length - 1 ?

            file.FileName.Substring(index) : ".docx";

            file.CopyTo(stream);

            stream.Position = 0;


            WordDocument document = WordDocument.Load(stream, GetFormatType(type.ToLower()));

            string sfdt = Newtonsoft.Json.JsonConvert.SerializeObject(document);

            document.Dispose();

            return sfdt;

      

            }

        }

    }

}

我发出 Ajax 请求,以我的 doc(x) 文件作为参数调用此 .Net 方法。


执行 loadFile 函数时,我在浏览器的控制台中收到此错误:“跨源请求(阻止多源请求):“同源”策略不允许查阅位于https://localhost上的远程资源:5001/Syncfusion/Import。原因:CORS 请求失败。”


我按照本教程和那些 SO 发布Link1 Link2但它不起作用。有什么想法可以解决这个问题吗?



ITMISS
浏览 159回答 1
1回答

牧羊人nacy

你的代码看起来不错。我的猜测是,Firefox 与您的 asp.net 核心应用程序的自签名开发证书存在问题。我们过去曾多次遇到这种情况,Firefox 错误消息总是有点误导。我们为“修复”它所做的是:在 Firefox 中打开https://localhost:5001您现在应该在 Firefox 中看到证书错误“信任”自签名证书/为其添加例外再次尝试您的 api 调用。它现在应该可以工作
打开App,查看更多内容
随时随地看视频慕课网APP