В приведенном ниже коде я пытаюсь передать эти 4 параметра, но «источник» и «кампания» не отправляются.Вывод при вызове в Controller.java:
"email: имя пользователя MYemail: MYusername источник: null campaign: null"
Любая помощь будет очень признательна!
Код Swift:
var params = [String: AnyObject]()
params = ["email":"MYemail" as AnyObject,
"username":"MYusername" as AnyObject,
"source":"MYsource" as AnyObject,
"campaign":"MYcamp" as AnyObject]
var url = "http://localhost:5000/makeCall"
Alamofire.request(url, method: .post, parameters: params, encoding: JSONEncoding.default, headers: headers).validate().responseJSON { response in
print(" ==> jsonResone \(response)")
let jsonResponse = JSON(response.result.value!)
print(" ==> jsonResponse \(jsonResponse)")
}
Код Java бэкенда:
Controller.java:
@RequestMapping(value = {"/makeCall"}, method = RequestMethod.POST , produces = MediaType.APPLICATION_JSON_VALUE , consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity makeCall(@RequestBody MyModel myModel, HttpServletRequest request, HttpServletResponse response) throws ServiceException{
System.out.println("email: "+myModel.getEmail()+" username: "+myModel.getUsername()+" source: "+myModel.getSource()+" campaign: "+myModel.getCampaign());
ResponseEntity responseEntity = new ResponseEntity();
responseEntity.setResponse("this is the response");
responseEntity.setMessage("Success.");
responseEntity.setSuccess(true);
responseEntity.setStatusCode(200);
return responseEntity;
}
MyModel.java:
public class MyModel {
private String email;
private String username;
private String source;
private String campaign;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUsername() {
return username;
}
public void setUsername(String username){
this.username = username;
}
public String getSource(){
return source;
}
public void setSouce(String source){
this.source = source;
}
public String getCampaign(){
return campaign;
}
public void setCampaign(String campaign){
this.campaign = campaign;
}
}