2

I have a SpringBoot application with a @Controller that accepts a getRequest to localhost:8080/all and returns JSON. I have entered this domain in the browser and see the returned JSON.

However, when I attempt to hit this url with an Axios get request from my React app (which is running locally), rather than returning the JSON data, it returns the following error:

Network Error at createError (http://localhost:3000/static/js/bundle.js:1634:15) at XMLHttpRequest.handleError (http://localhost:3000/static/js/bundle.js:1170:14)

I checked Chrome's network tab for the get request and it doesn't return anything for the preview or response, but does indicate:

Request URL: https://localhost:8080/all
Referrer Policy: no-referrer-when-downgrade

in the Headers section.

Both applications are running locally and when I try a different axios get request (for a different API) it returns the JSON successfully. How can I successfully return JSON from my Spring Boot application?

The React setup for the API call is:

  componentDidMount() {
    axios.get('https://localhost:8080/all')
    .then(function (response) {

      console.log(response);
    })
    .catch(function (error) {

      console.log(error);
    });
  }

And the controller action in the Spring Boot app is:

@RestController    
public class UserController {

    @Autowired
    UserJDBCDao dao;

    @GetMapping(path="/all")
    public @ResponseBody Iterable<User> getAllUsers() {
        // This returns a JSON or XML with the users
        return dao.findAll();
    }


}
4
  • 1
    What does your network tab of chrome show? Commented Dec 10, 2018 at 1:46
  • i updated with that info. Commented Dec 10, 2018 at 1:48
  • 1
    what about error log of spring boot application? Commented Dec 10, 2018 at 1:53
  • that was it. i had to change https to http Commented Dec 10, 2018 at 1:57

1 Answer 1

1

After checking the Spring Boot error log it indicated:

java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens

So I changed https to http and the request worked. I'm not sure if this is the most secure way, so someone else might have a better solution.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.