title: Cors Error with Post mapping in Spring boot
body: <p>I have a Spring boot application with a rest controller and an Angular application as frontend. 
  For the moment they are both running in localhost and SpringSecurity is enabled is Spring.
  Originally I was unable the make a getRequest from Angular to Spring because of Cors. I added @CrossOrigin to my restContoller and now I'm able to do a Get request from angular to Spring.
  Now I have the same problem with post request. I want to send some form data from angular to Spring but I always get an error in Chrome. I added @CrossOrigin here as well but I still have the problem.
  If I try a post request with postmen it's working just fine </p>
  
  <p>zone.js:3243 Access to XMLHttpRequest at 'localhost:8080/rest/contact' from origin '<a href="http://localhost:4200" rel="noreferrer">http://localhost:4200</a>' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.</p>
  
  <p>contact.component.ts:51 HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: "localhost:8080/rest/contact", ok: false, …}</p>
  
  <p>This is my security configuration:</p>
  
  <pre><code>@EnableGlobalMethodSecurity(prePostEnabled = true)
  @Configuration
  @EnableWebSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Autowired
      private CustomUserDetailsService userDetailsService;
  
      @Override
      protected void configure (AuthenticationManagerBuilder auth) throws Exception {
          auth.userDetailsService(userDetailsService)
          .passwordEncoder(getPasswordEncoder());
      }
  
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.cors();
          http
                  .authorizeRequests()
                  .antMatchers("/admin/**").authenticated()//.hasAnyRole("ADMIN","USER")
                  .and().formLogin().loginPage("/login").permitAll()
                  .and().logout();
          http.csrf().disable();
          //http.headers().frameOptions().disable();
      }
  
  
      private PasswordEncoder getPasswordEncoder() {
          return new PasswordEncoder() {
              @Override
              public String encode(CharSequence charSequence) {
                  return charSequence.toString();
              }
  
              @Override
              public boolean matches(CharSequence charSequence, String s) {
  
                  return encode(charSequence).equals(s);
              }
          };
      }
  }
  </code></pre>
  
  <p>My Cors configuration:</p>
  
  <pre><code>@Configuration
  public class CorsConfiguration {
  
      @Bean
      public WebMvcConfigurer corsConfigurer() {
          return new WebMvcConfigurerAdapter() {
              @Override
              public void addCorsMappings(CorsRegistry registry) {
                  registry.addMapping("/**");
              }
          };
      }
  }
  </code></pre>
  
  <p>My rest controller:</p>
  
  <pre><code>@RestController()
  @CrossOrigin(origins = "http://localhost:4200/**", maxAge = 3600)
  public class GymRestController {
  
      private final GymRepository gymRepository;
  
      GymRestController (GymRepository gymRepository) {
          this.gymRepository = gymRepository;
      }
  
      @GetMapping("/rest/gyms")
      public List&lt;Gym&gt; findAll() {
          return gymRepository.findAll();
      }
  
      @PostMapping ("/rest/contact")
      public void submitContact(@RequestBody ContactForm contactForm) {
          System.out.println(contactForm);
  
      }
  }
  </code></pre>
  
  <p>and my on submit method in angular</p>
  
  <pre><code>  onSubmit() {
      this.submitted = true;
  
      if (this.messageForm.invalid) {
          return;
      }
  
      this.success = true;
  
      this.contactModel.fromName = this.messageForm.get('name').value;
      this.contactModel.fromMail = this.messageForm.get('email').value;
      this.contactModel.subject = this.messageForm.get('subject').value;
      this.contactModel.message = this.messageForm.get('message').value;
  
      let url = "http://localhost:8080/rest/contact";
      // let url = "https://cors.io/?localhost:8080/rest/contact"
      this.http.post(url, this.contactModel).subscribe(
        res =&gt; console.log("success"),
        error =&gt; console.log(error),
        () =&gt; console.log("complete")
      );
  
  
    }
  </code></pre>
  
  <p>I've been trying for 3 days to get this working without any luck
  Any help would be appreciated</p>