【问题标题】: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 中请求的方法的请求资源支持
【发布时间】:2015-05-26 09:44:56
【问题描述】:

我必须从 Flex 调用 Java 中的一个方法,该方法使用 JSON 并将信息保存在 DB 中。当我从 JSP 调用它时,它接受输入,但是当我从 Flex 应用程序调用它时,它给了我错误 "服务器拒绝了这个请求,因为请求实体的格式不受所请求方法的请求资源支持"

下面是我的 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();
     }

}

【问题讨论】:

    标签: java json actionscript-3 apache-flex httpservice


    【解决方案1】:
    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);
    

    【讨论】:

    • 嗨,吉勒尼。感谢您的快速回复。我修改了类似 urs 的代码。现在它说“客户端发送的请求在语法上不正确。”
    • 这是一个请求映射错误,能把服务方法贴一下吗?
    • try : public void save(@RequestParam(value = "p") Person person)throw Exception{ ...}
    • 试过上面的修复还是说客户端发送的请求语法不正确
    猜你喜欢
    • 2014-07-26
    • 2019-04-28
    • 2018-01-19
    • 2015-05-19
    • 1970-01-01
    • 2021-01-04
    • 2018-06-24
    • 2013-03-19
    相关资源
    最近更新 更多