Athe
Athe

Reputation: 43

Postman :"status": 404, "error": "Not Found", "message": "Not Found" in Java

I have a Java program that uses Postman. I am trying to make a post request on Postman. My code:

@RestController()
@RequestMapping("/v1/e")
public class EC {
    @PostMapping(path = "{document}", consumes = "application/json", produces = "application/json")
    public ResponseEntity<InputStreamResource> createDocument(@PathVariable Dtype document,@RequestBody String data){
        //code
    }

Below is the URL I am using to post:

http://localhost:8080/v1/e?document=E_PC

However, I am getting the following error:

{
    "timestamp": "2020-08-05T02:22:03.008+0000",
    "status": 404,
    "error": "Not Found",
    "message": "Not Found",
    "path": "/v1/e"
}

Upvotes: 1

Views: 13589

Answers (2)

Mohamed Hamras
Mohamed Hamras

Reputation: 1

This would work fine:

@RestController()
@RequestMapping("/v1/e/{document}")
public class EC {
    @PostMapping
    public ResponseEntity<InputStreamResource> createDocument(@PathVariable Dtype document,@RequestBody String data) {
        //code
    }

Upvotes: 0

Abdusoli
Abdusoli

Reputation: 659

You can also use like below:

@RestController
@RequestMapping("/v1/e")
public class EC {

  @PostMapping
  public ResponseEntity<?> createDocument(@RequestParam("document") String document){
      //code
  }

}

And your POST REQUEST is http://localhost:8080/v1/e?document=E_PC

Upvotes: 0

Related Questions