title: how can I send a string from angular 6 to springboot rest controller?
body: <p>I want to pass a single string from angular 6 using post to the springboot server controller, but it always fails with the httpErrorResponse 403, and error message is "forbidden", I am new to angular, hope someone can help me , thanks a lot. My java version is 10.
  Following is my related code:</p>
  
  <p>component.html:</p>
  
  <pre><code>&lt;p-button label="Stop" styleClass="ui-button-danger" (onClick)="send()"&gt;&lt;/p- 
   button&gt;
  {{result}}
  </code></pre>
  
  <p>component.ts:</p>
  
  <pre><code>export class TestComponent implements OnInit {
    selectedFile: string;
    selectedFile = "20180812";
    result: string;
    constructor(private cityService: CityService) {}
  
    send() {
    //pass a string  selectedFile
    this.cityService.send(this.selectedFile).subscribe(data=&gt; this.result = 
    data);
    }
  } 
  </code></pre>
  
  <p>service.ts:</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import {HttpClient, HttpHeaders} from "@angular/common/http";
  import {Observable} from "rxjs/internal/Observable";
  @Injectable({
    providedIn: 'root'
  })
  
  export class CityService {
    private testUrl = '//localhost:8080/sendString';
    constructor(private http: HttpClient) { }
  
    send(s: string): Observable&lt;any&gt; {
        return this.http.post(this.testUrl, s, {
            headers: new HttpHeaders({
              'Content-Type': 'text/plain'
            })
        });
     }
    }
  </code></pre>
  
  <p>controller.java:</p>
  
  <pre><code>@CrossOrigin(origins = "http://localhost:4200")
  @RestController
  public class TestController {
  
  @RequestMapping(value = "/sendString", method = RequestMethod.POST,consumes = 
                  "text/plain")
  public String pass(@RequestBody String test1) {
      System.out.println(test1);
      return test1;
  }}
  </code></pre>
  
  <p>Error message on chrome browser:<a href="https://i.stack.imgur.com/rF7X8.png" rel="nofollow noreferrer">The error screenshot</a></p>
  
  <p>securityConfig.java:</p>
  
  <pre><code>package com.predicine.sbproto.security;
  
  import *;
  
  @Configuration
  @EnableGlobalMethodSecurity( securedEnabled = true)
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
  }
  </code></pre>
  
  <p>application.property:</p>
  
  <pre><code>#Security Configuration
  spring.security.user.name=user
  spring.security.user.password=user
  spring.security.user.roles=USER
  </code></pre>