Angular application error ,calling back-end api POST /users with Content-Type:text/plain
ajitkumargiri opened this issue · comments
I am trying in local to register through angular app but not able to call api backend.
I debug it and found below error.
Request URL:http://localhost:8080/users
Request Method:POST
Status Code:415
Remote Address:[::1]:8080
Referrer Policy:no-referrer-when-downgrade
Accept:application/json, text/plain, /
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.9
Connection:keep-alive
Content-Length:64
Content-Type:text/plain
Host:localhost:8080
Origin:http://localhost:4200
Referer:http://localhost:4200/register
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36
You may have to set proper HTTP headers.
Current course is based on Angular2, so you may find some code in the "m-X" branches that deal with it in api service. A better way to do it has been recently merged in master, that is based on newer http client module, and interceptors. More info here: 96277cb
96277cb
I think there is error. Because of
const headersConfig = {
'Content-Type': 'application/json',
'Accept': 'application/json'
};
const token = this.jwtService.getToken();
if (this.jwtService.getToken()) {
headersConfig['Authorization'] = 'Token ${this.jwtService.getToken()}';
const authReq = req.clone({ setHeaders: headersConfig });
return next.handle(authReq);
}
so only if you will get token - headers will be set. But you do not have any token when you need to register user. I provide PR that fix this issue #80
@ajitbapina you can close this issue, changes merged to master
closed via #80