设置JSON内容类型上S:HttpService的在弯曲 [英] Set JSON content-type on s:HttpService in flex

查看:208
本文介绍了设置JSON内容类型上S:HttpService的在弯曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置的HTTPService的JSON内容类型,以REST服务返回的JSON数据。当我添加的内容类型的小提琴手一切工作正常,所以问题奠定Flex中的应用,而不是在web服务。但是,code以下不工作,我得到的XML数据,而不是JSON。

任何人都可以向我提供了解决方法/解决方案?

MXML:

 < S:的HTTPService的id =服务的方法=POSTURL =server.com
               结果=装(事件)故障=故障(事件)
               =并将useProxy假的resultFormat =文本>
 

动作:

 公共职能loadAllSamples():无效{
    service.contentType =应用/ JSON;
    service.send('东西');
}
 

解决方案

看起来我已经整理出来。诀窍是,接受头部应在服务中加入:

  VAR头:对象=新的对象();

        **标题[接受] =应用/ JSON的**

        service.contentType =应用/ JSON;
        service.headers =报头;
        service.send('{}');
 

我想这可能是别人有帮助的。祝你好运。

I am trying to set the json content type on httpservice to make REST service return the json data. When I add the content type in fiddler all works fine so the problem lays in flex application, not in the web-service. But the code below does not work and I get the xml data instead of json.

Could anyone provide me the workaround/solution?

mxml:

<s:HTTPService id="service" method="POST" url="server.com" 
               result="loaded(event)" fault="fault(event)" 
               useProxy="false" resultFormat="text">

actionscript:

public function loadAllSamples():void {
    service.contentType = "application/json";
    service.send('something');
}

解决方案

Looks like I have sorted it out. The trick is that Accept header should be added on service:

       var header:Object=new Object();

        **header["Accept"] = "application/json";**

        service.contentType = "application/json";
        service.headers = header;
        service.send('{}');

I wish it could be helpful for somebody. Good luck.

这篇关于设置JSON内容类型上S:HttpService的在弯曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆