在下面的代码中,我试图传递这4个参数,但是未发送“源”和“广告系列”。当呼叫在Controller.java由输出是
“电子邮件:MYemail用户名:MYusername来源:空广告系列:空”
任何帮助将不胜感激!
快捷代码:
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;
}
}