igu*_*igu 7 apache-flex json actionscript httpservice
我试图在httpservice上设置json内容类型,以使REST服务返回json数据.当我在fiddler中添加内容类型时,所有工作正常,因此问题在flex应用程序中,而不是在Web服务中.但是下面的代码不起作用,我得到xml数据而不是json.
有人能为我提供解决方法/解决方案吗?
MXML:
<s:HTTPService id="service" method="POST" url="server.com"
result="loaded(event)" fault="fault(event)"
useProxy="false" resultFormat="text">
Run Code Online (Sandbox Code Playgroud)
动作:
public function loadAllSamples():void {
service.contentType = "application/json";
service.send('something');
}
Run Code Online (Sandbox Code Playgroud)
igu*_*igu 12
看起来我已经整理出来了.诀窍是应该在服务上添加Accept标头:
var header:Object=new Object();
**header["Accept"] = "application/json";**
service.contentType = "application/json";
service.headers = header;
service.send('{}');
Run Code Online (Sandbox Code Playgroud)
我希望它对某人有帮助.祝好运.
| 归档时间: |
|
| 查看次数: |
8889 次 |
| 最近记录: |