Reactjs TypeError:NetworkError在Firefox中发布期间尝试在fetch中获取资源时出错

Reactjs TypeError:NetworkError在Firefox中发布期间尝试在fetch中获取资源时出错,reactjs,spring-boot,firefox,httprequest,fetch,Reactjs,Spring Boot,Firefox,Httprequest,Fetch,我正在尝试使用fetch从同一台机器上的React应用程序向我的Spring引导服务器发送POST请求。我允许从RestController类中使用CrossOrigin。当我使用Opera浏览器时,GET和POST请求都可以正常工作。使用Firefox,我可以通过使用fetch获取数据。但是当我使用fetchtopost时,我无法访问服务器和Firefox控制台 TypeError: NetworkError when attempting to fetch resource. 这是我的GE

我正在尝试使用fetch从同一台机器上的React应用程序向我的Spring引导服务器发送POST请求。我允许从RestController类中使用CrossOrigin。当我使用Opera浏览器时,GET和POST请求都可以正常工作。使用Firefox,我可以通过使用fetch获取数据。但是当我使用fetchtopost时,我无法访问服务器和Firefox控制台

TypeError: NetworkError when attempting to fetch resource.
这是我的GET请求代码:

fetch('http://localhost:8080')
    .then(response => response.json())
    .then(data => this.setState({messages: data, currentUser: data[0].sender, isLoading: false}));
这是邮政编码:

fetch('http://localhost:8080', {
    method: 'POST',
    mode: 'cors',
    cache: 'no-cache',
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({text: this.state.newMessageText, sender: this.state.currentUser})
});
我尝试了删除模式、缓存和标题区域,但不起作用。 这是我的服务器类:

package com.ybalcanci.eternalchat.controller;

import com.ybalcanci.eternalchat.model.Message;
import com.ybalcanci.eternalchat.repository.MessageRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/")
@CrossOrigin(origins = {"http://localhost:3000", "http://localhost:5000"})
public class MainController {

    @Autowired
    private MessageRepository messageRepository;

    @PostMapping
    public Message newMessage(@RequestBody Message message) {
        System.out.println("New Post Request: " + message);
        return messageRepository.save(message);
    }

    @GetMapping
    public List<Message> messages(){
        return messageRepository.findAll();
    }
}
包com.ybalcanci.eternalchat.controller;
导入com.ybalcanci.ternalchat.model.Message;
导入com.ybalcanci.eternalchat.repository.MessageRepository;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.web.bind.annotation.*;
导入java.util.List;
@RestController
@请求映射(“/”)
@交叉原点(原点={”http://localhost:3000", "http://localhost:5000"})
公共类主控制器{
@自动连线
私有消息存储库消息存储库;
@邮戳
公共消息newMessage(@RequestBody Message){
System.out.println(“新的Post请求:+消息”);
返回messageRepository.save(消息);
}
@GetMapping
公共列表消息(){
return messageRepository.findAll();
}
}