小编Abd*_*dul的帖子

React 组件已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头

当我过去将它作为一个应用程序运行时,我正在使用 fetch 从我的 react 组件调用 Web API,没有问题,但是当我运行应用程序 react 与 API 分开时,我收到 CORS 错误,我的 fetch 调用如下,

    componentDidMount() {
    console.log(clientConfiguration)

    fetch(clientConfiguration['communitiesApi.local'])
        .then((response) => {
            return response.json();                
        })
        .then(data => {
            console.log(data);
            let communitiesFromApi = data.map(community => { return { value: community, display: community } });
            this.setState({ communities: [{ value: '', display: 'Select a Community...' }].concat(communitiesFromApi) });    

        }).catch(error => {
            console.log(error);
        });
};
Run Code Online (Sandbox Code Playgroud)

和我的 POST 调用也使用 Axios,如下所示。

    handleDownload = (e) => {
    e.preventDefault();

    var formData = new FormData();
    formData.append('communityname', this.state.selectedCommunity);
    formData.append('files', JSON.stringify(this.state['checkedFiles']));

    let …
Run Code Online (Sandbox Code Playgroud)

javascript asp.net-web-api reactjs

5
推荐指数
2
解决办法
2万
查看次数

使用 React 从 FileStream 返回下载文件

您好,我有一个如下图所示的 Web api - 返回 HttpResponseMessage,我将 fileStream 作为其内容重新设置,当我尝试在控制台上检索或将其记录为 console.log(response.data) 时,它会显示一些其他信息,但是不是流信息或数组或任何此类内容。有人可以帮助我如何使用 React 读取或下载作为流或 FileStream 返回的文件。我没有使用 jQuery。请提供任何帮助,链接或类似的东西。我可以使用字节数组下载文件,但需要使用 FileStream 来实现,请问有什么帮助吗?

        [EnableCors("AnotherPolicy")]
    [HttpPost]
    public HttpResponseMessage Post([FromForm] string communityName, [FromForm] string files) //byte[]
    {
        HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);

        var removedInvalidCharsFromFileName = removeInvalidCharsFromFileName(files);
        var tFiles = removedInvalidCharsFromFileName.Split(',');
        string rootPath = Configuration.GetValue<string>("ROOT_PATH");
        string communityPath = rootPath + "\\" + communityName;

        byte[] theZipFile = null;
        FileStreamResult fileStreamResult = null;

        using (MemoryStream zipStream = new MemoryStream())
        {
            using (ZipArchive zip = new ZipArchive(zipStream, ZipArchiveMode.Create, true))
            {
                foreach (string …
Run Code Online (Sandbox Code Playgroud)

javascript asp.net-web-api reactjs

4
推荐指数
1
解决办法
1万
查看次数

React中的插值不能以这种方式工作,有人可以在这方面帮助我吗?

我正在尝试插值

var sample = "test";
var result = 'this is just a ${sample}'; 
alert(result);                         
Run Code Online (Sandbox Code Playgroud)

它没有用,只是在发出警报,这只是$ {sample},有人可以在这方面帮助我吗?谢谢

javascript reactjs

3
推荐指数
1
解决办法
37
查看次数

标签 统计

javascript ×3

reactjs ×3

asp.net-web-api ×2