новые HttpHeaders 415 erroe - PullRequest
       3

новые HttpHeaders 415 erroe

0 голосов
/ 19 сентября 2019

Я исследовал вопрос о различных ссылках здесь и других ресурсах.У меня ничего не работает.Пожалуйста, помогите мне найти ошибку

import {HttpHeaders} from '@angular/common/http';
handleSubmit = async event => {

       event.preventDefault();
       this.setState({isloading: true});
       console.log(this.state);
       const headers = new HttpHeaders().set('Content-Type', 'application/json')
           .append('Access-Control-Allow-Origin', 'http://localhost:8080')
           .append('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
       .append('Access-Control-Allow-Origin','http://localhost:8080')
           .append('Accept','application/json')
       return fetch('http://localhost:8080/registration', {
           mode:"no-cors",
           method: 'POST',
           body: JSON.stringify(this.state),
           headers: headers,
           responseType: 'text'}).then(response => {
           console.log(response)
       })
           .catch(error => {
               console.log(error)
           })
   };

и мой UserController.java

@RequestMapping(value = "/registration", method = {RequestMethod.POST}, produces={"application/json"})
    @ResponseBody
    public ResponseEntity<User> registration(@RequestBody  User user, HttpStatus httpStatus) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.valueOf(MediaType.APPLICATION_JSON_UTF8_VALUE));
         userService.saveUser(user);
         return new ResponseEntity<>(headers, HttpStatus.CREATED);
    }

Я видел метод в одном из вопросов здесь.Но все равно это не работает

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...