I have to call a method in Java from Flex which consumes JSON and saves info in DB. When I call it from JSP it accepts the input but when I call it from Flex application it gives me the error "The server refused this request because the request entity is in a format not supported by the requested resource for the requested method"
Below is my sample code from Flex.
var p:Object = new Object();
p.firstName = 'Mary';
p.lastName = 'Thomas';
p.gender = 'Female';
var httpServ:HttpService = new HttpService();
httpServ.url ="http://localhost/samplewebservice/myPerson/insert";
httpServ.useProxy = false;
httpServ.method = "POST"
httpServ.headers = {Accept: 'application/x-www-form-urlencoded'}
httpServ.contentType = "application/x-www-form-urlencoded";
var jd:JSONEncoder = new JSONEncoder(p);
var s:String = jd.getString();
httpServ.send(s);
Please let me Know where it went wrong. Thanks in advance
My service Code
@POST
@Path("/insert")
@consumes(MediaType.APPLICATION_JSON)
@RequestMapping(value = "/insert")
public void save(@RequestBody Person person)throws Exception{
try{
myservice.insert(person);
}
catch(Exception e)
{
e.printStacktrace();
}
}
var httpServ:HttpService = new HttpService();
httpServ.url ="http://localhost/samplewebservice/myPerson/insert";
httpServ.method = "POST";
httpService.contentType="application/json";
var header:Object=new Object();
header["Accept"] = "application/json";
httpService.headers = header;
var p:Object = new Object();
p.firstName = 'Mary';
p.lastName = 'Thomas';
p.gender = 'Female';
var params:Object=JSON.encode(p);
httpService.send(params);