title: Reactjs application can not reach my Spring Boot backend using https requests
body: <p>I have a ReactJS application running on <a href="https://localhost:8080" rel="nofollow noreferrer">https://localhost:8080</a> and i would like to POST data to my Spring Boot backend app running on <a href="https://localhost:8443" rel="nofollow noreferrer">https://localhost:8443</a>, but when i try to POST data..i get this error in my browser console:</p>
  
  <p>TypeError: "NetworkError when attempting to fetch resource."
  Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at <a href="https://localhost:8443/api/" rel="nofollow noreferrer">https://localhost:8443/api/</a>... (Reason: CORS request did not succeed).</p>
  
  <p>My Spring Boot application not using Spring Security. I enabled HTTPS by <a href="https://www.tutorialspoint.com/spring_boot/spring_boot_enabling_https.htm" rel="nofollow noreferrer">this</a> tutorial. I running my ReactJS application with <code>HTTPS=true npm start</code> and i changed the react application port like <code>"start": "PORT=8080 react-scripts start"</code> inpackage.json</p>
  
  <p>This is my application.properties:</p>
  
  <pre><code>server.ssl.key-store-password = password
  server.ssl.key-store-type = PKCS12
  server.ssl.key-alias = tomcat
  server.ssl.enabled=true
  </code></pre>
  
  <p>and here is how t tried to call the REST API from React:</p>
  
  <pre><code>fetch('https://localhost:8443/api/..., {
              method: 'POST'
          }).then((data) =&gt; {
              if (data.ok) {
                  this.setState({ 
                  response: data })
              }
          })
          .catch(console.log);
  </code></pre>
  
  <p>Here is my @RestController:</p>
  
  <pre><code>@RestController
  @RequestMapping("/api")
  public class MessageReceiverResource {
  
      @CrossOrigin(origins = "https://localhost:8080")
      @PostMapping
      public Response receiveMessages(@RequestBody Request request){
             ...
          return response;
      }
  }
  
  </code></pre>
  
  <p>This solution just worked fine until I enabled HTTPS.</p>