服务器拒绝此请求,因为请求实体的格式不受 Flex 中请求方法的请求资源支持
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method in Flex
我必须从 Flex 调用 Java 中的方法,该方法使用 JSON 并将信息保存在数据库中。当我从 JSP 调用它时它接受输入但是当我从 Flex 应用程序调用它时它给我错误
"The server refused this request because the request entity is in a format not supported by the requested resource for the requested method"
下面是我来自 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);
请让我知道哪里出了问题。提前致谢
我的服务代码
@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);
我必须从 Flex 调用 Java 中的方法,该方法使用 JSON 并将信息保存在数据库中。当我从 JSP 调用它时它接受输入但是当我从 Flex 应用程序调用它时它给我错误 "The server refused this request because the request entity is in a format not supported by the requested resource for the requested method"
下面是我来自 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);
请让我知道哪里出了问题。提前致谢
我的服务代码
@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);