I am working with Spring MVC and I use simple HTML form. I am sending HTTPS request to gracenote using GET method but I need to do it using POST method. With GET it works fine but I can not get it to work with POST method. And I need to recieve JSON response not XML. Is it even possible to do it with POST method and recieve JSON response ? I know that by constructing XML request link I send via POST method but then I recieve XML response ( info: https://github.com/richadams/java-gracenote ).
Code for GET method:
My HTML form in recommended.jsp
<spring:url value="/recommendedSongs.view" var="formUrl"/>
<form:form action="${formUrl}" method="POST" modelAttribute="command">
<form:label path="artistName">Artist name</form:label>
<form:input path="artistName" id="artistInput"/>
<form:label path="trackTitle">Track title</form:label>
<form:input path="trackTitle" id="trackInput"/>
<input type="submit" value="Submit"/>
</form:form>
Model getters and setters
public class RecommendedFormDataCommand {
private String artistName;
private String trackTitle;
public String getArtistName() {
return artistName;
}
public void setArtistName(String artistName) {
this.artistName = artistName;
}
public String getTrackTitle() {
return trackTitle;
}
public void setTrackTitle(String trackTitle) {
this.trackTitle = trackTitle;
}
}
Controller code to recieve data from HTML form
@RequestMapping(value = "/recommended.view")
public ModelAndView artistTrackForm() {
return new ModelAndView("recommended", "command", new RecommendedFormDataCommand());
}
@RequestMapping(value = "/recommendedSongs.view")
public String artistTrackFormData(@ModelAttribute("command") RecommendedFormDataCommand rfd,
ModelMap model) throws IOException {
HTTPS GET request
https://{CLIENT ID}.web.cddbp.net/webapi/json/1.0/radio/recommend?client={CLIENT ID}-{CLIENT TAG}&user={CLIENT ID}&seed=(text_artist_kendrick+lamar;text_track_King+Kunta%2Cking+kunta)&return_count=25
NOTE: I do not want to show my client tag and id so I replaced them with these: {CLIENT ID} and {CLIENT TAG}
It would be really helpful if someone could tell me if it is possible to send HTTPS request via POST method and recieve JSON response aand give simple example.