在我的开发环境中,我有一个使用Spring Boot构建的BE和使用React.js(Redux + Axios)构建的FE。每当我尝试使用Axios执行HTTP POST时,我都会禁止403。 HTTP GET调用按预期工作,Postman的HTTP POST调用也正常工作。
@RestController
@RequestMapping(value = "/api/v1/person")
public class PersonController {
@Autowired
private PersonRepository mPersonDAO;
@PostMapping
public ResponseEntity<Person> create(@RequestBody Person person) {
Person result = mPersonDAO.save(person);
return new ResponseEntity<>(result, HttpStatus.CREATED);
}
}
import axios from 'axios';
const BASE_URL = 'https://localhost:8080/api/v1';
const PERSON_API = BASE_URL + '/person'
export function syncUser (person, onSuccess) {
axios({
method: 'post',
url: PERSON_API,
data: {
person
}
}).then((response) => {
onSuccess(response);
}).catch(function (error) {
console.log(error);
});
}
localhost/:1 XMLHttpRequest cannot load http://localhost:8080/api/v1/person.
dispatchXhrRequest @ xhr.js:177
xhrAdapter @ xhr.js:12
dispatchRequest @ dispatchRequest.js:52
Response for preflight has invalid HTTP status code 403