1

I'm trying to send data from Vue to Spring

I've been searching everywhere and everything looks perfect but still it doesn't work

At first I was thinking may be because my class in back have more fields than what I send from front but even though I created another class with same fields it doesn't work

Here is my send request:

sendRequest() {
  console.log(this.user);
  (this.loading = true),
    axios.get("http://localhost:8081/user/log-in", this.user)
      .then((response) => {
        console.log(response);
      })
      .catch((error) => {
        (this.isShow = true),
          (this.isHide = false),
          (this.showAlert = true),
          (this.message = error.response.data);
        (this.showMessage = true),
          setTimeout(
            function () {
              this.showMessage = false;
              (this.isShow = false), (this.isHide = true);
            }.bind(this),
            3000
          );
      })
      .finally(() => {
        this.loading = false;
      });

Here data I send from front to back:

      user: {
    userName: "",
    password: ""
  },

Here my back end class that get data:

public class UserSignUpDTO {

private String firstName;

private String userName;

private String email;

private String password;

private String birthDay;

}

And here is the method that get data:

    @GetMapping("/log-in")
public UserDTO logInUser(@RequestBody UserSignUpDTO user) throws Exception {
    return userService.logInUser(user);
}

Mapping for request:

@RestController
@RequestMapping("/user")
public class UserController {

1 Answers1

0

It is not advisable to use a GET with a request body. While HTTP/1.1 does not seem to explicitly forbid this, it should not have meaning.

As hinted here,

If you give it meaning by parsing it on the server and changing your response based on its contents, then you are ignoring this recommendation in the HTTP/1.1 spec, section 4.3.

I would advise you use a POST request in this case.

Change this

axios.get("http://localhost:8081/user/log-in", this.user)

To this

axios.post("http://localhost:8081/user/log-in", this.user)
Rotiken Gisa
  • 380
  • 2
  • 12