I am trying to save my data in Firebase database through calling POST request to Springboot REST server. But then the result is keep coming back 415 Unsupported Media Type.
I've tried all the solutions provided in the net but then I still getting 415 error.
POST function itself does work in postman and saves to the Firebase database correctly.
I've added Content-Type and Accept to accept application/json
This is my Customer controller in Springboot:
@CrossOrigin(origins = "http://localhost:3000")
@RestController
@RequestMapping("/customerService")
public class CustomerController {
@Autowired
public CustomerService customerService;
@PostMapping("/create")
public String createCustomer(@RequestBody Customer customer) throws InterruptedException, ExecutionException {
return customerService.createCustomer(customer);
}
@GetMapping("/get")
public Customer getCustomer(@RequestParam String userName) throws InterruptedException, ExecutionException{
return customerService.getCustomer(userName);
}
@PutMapping("/update")
public String updateCustomer(@RequestBody Customer customer) throws InterruptedException, ExecutionException{
return customerService.updateCustomer(customer);
}
@PutMapping("/delete")
public String deleteCustomer(@RequestParam String document_id) throws InterruptedException, ExecutionException{
return customerService.deleteCustomer(document_id);
}
}
This is how I am calling POST request in React
let payload = {
"email": "customer2@gmail.com",
"userName": "customer2",
"password": "password",
"phoneNumber": "1234567890"
}
const requestOptions = {
method: "POST",
headers: {'Accept': 'application/json','ContentType':"application/json"},
body:JSON.stringify(payload),
}
fetch("http://localhost:8080/customerService/create", requestOptions)
.then(response => response.json())
.then(data =>{
}
This is the error I am getting:
Using the mode: 'no-cors', produces the same error with different wording for some reason
