i wanna post a simple http request , but the backend can not receive the paramter
export class AppComponent {
isMenuCollapsed$:Observable<boolean>;
constructor(private store:Store<reducers.State>,private http:Http) {
this.isMenuCollapsed$ = this.store.select(reducers.getIsCollapsed);
let body: URLSearchParams = new URLSearchParams();
body.set('username', 'admin');
body.set('password', 'admin');
let head = new Headers({
'Content-Type': 'application/json'
});
http.post('api/user/auth',body).subscribe(v => console.log(v));
}
}
this is my backend code:
@RestController
@RequestMapping("/user")
public class TestController {
@GetMapping("/get")
public String test(){
return "hello";
}
@PostMapping("/auth")
public String auth(HttpServletRequest request){
return "username:" + request.getParameter("username") +
"|password:" + request.getParameter("password");
}
}
when i use regular method it worked:
but when i use angular http , return null enter image description here
so i hope someone can help me , thanks!!!