Getting 415 Error on updating using PUT method

Viewed 18

I am using JWT spring security in backend and I would like to update user details in angular using PUT method. But I am getting 415 error on update.

Update method in springboot controller

@PutMapping("/UpdateUser/{id}")
public ResponseEntity<User> updateUsers(@PathVariable("id") Long id,@RequestBody User user){
    User update = userService.updateUser(user);
    return new ResponseEntity<>(update, HttpStatus.OK);
}

Angular service

    import { HttpClient, HttpHeaders } from '@angular/common/http';
    import { Injectable } from '@angular/core';
    import { UserAuthService } from './user-auth.service';
    
    @Injectable({
      providedIn: 'root',
    })
    export class UserService {
      PATH_OF_API = 'http://localhost:9090';
    
      requestHeader = new HttpHeaders({ 'No-Auth': 'True' });
      constructor(
        private httpclient: HttpClient,
        private userAuthService: UserAuthService
      ) {}
    
      public sign(signData){
        return this.httpclient.post(this.PATH_OF_API + '/registerNewUser',signData,{
          headers:this.requestHeader
        });
      }
    
    
      updateUser(userId:number,user){
        return this.httpclient.put(this.PATH_OF_API + '/UpdateUser/'+userId,userId,user);
      }
}

Error

Error image

Request URL: http://localhost:9090/UpdateUser/1663565697945
Request Method: PUT
Status Code: 415 
Remote Address: [::1]:9090
Referrer Policy: strict-origin-when-cross-origin

**Response header**
Accept: application/json, application/*+json
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://localhost:4200
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Connection: keep-alive
Content-Type: application/json
Date: Mon, 19 Sep 2022 16:35:21 GMT
Expires: 0
Keep-Alive: timeout=60
Pragma: no-cache
Transfer-Encoding: chunked
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
**Request header**
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJrZWVydGhpMTIzIiwiZXhwIjoxNjYzNjE4MTc0LCJpYXQiOjE2NjM2MDAxNzR9.2YxIgdM78TZDNpwFIkB_-KfZ4DwlWKlN7Xzf4V4D2g4kCQr7kJdpx0ExbN9CTWAxtokzjlk_K22ROQEzBgGKnw
Connection: keep-alive
Content-Length: 13
Content-Type: text/plain
Host: localhost:9090
Origin: http://localhost:4200
Referer: http://localhost:4200/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors

{ "timestamp":"2022-09-19T16:35:21.514+00:00", "status":415, "error":"Unsupported Media Type", "message":"", "path":"/UpdateUser/1663565697945" }

How can I solve this error. Help me to solve this issue.

0 Answers
Related