0

I have this spring boot controller method:

@PostMapping(path = "/myPath")
public String methodName(@RequestBody String incoming) { ... 

However if I try to post an XML file to it with curl, like:

curl -X POST http://localhost:8080/myPath --data-binary @./my/path/my_file.xml

the incoming String is all escaped characters, like:

%3C%3Fxml+version=%221.0%22+encoding%3D%22UTF-8%...

and it blows up attempting to parse it with ...Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.

when it should be like <?xml version="1.0" what is going on?

rogerdpack
  • 62,887
  • 36
  • 269
  • 388

1 Answers1

0

Still not what was happening, but adding curl --header "Content-Type:text/xml" fixed it. I guess the default is application/x-www-form-urlencoded and the above overrides it, which is necessary, not sure why, maybe the web framework is assuming some extra encoding is necessary or what not. You can see which one it is using by running curl -v and make sure it's not urlencoded, apparently.

rogerdpack
  • 62,887
  • 36
  • 269
  • 388