【问题标题】:Always getting XML responses in FB 4.6在 FB 4.6 中总是得到 XML 响应
【发布时间】:2013-01-15 15:59:00
【问题描述】:

我正在使用请求和响应为 JSON 格式的 iOS 网络服务。通过 flash builder 访问此 Web 服务时,我收到了 XML 格式的响应。但在 iOS 中运行相同的应用程序会返回 JSON。

 private function service_activate(webservices:mx.rpc.http.HTTPService):void{

            var args:String=new String("{\"SessionGuid\":\""+sessionid.text +"\"}");
            webservices.resultFormat="text";
            webservices.contentType="application/json";
            webservices.send(args);
           }

    <fx:Declarations>
        <s:HTTPService id="webservice"
                   url="http://webservices..."
                   method="POST" contentType="application/x-www-form-urlencoded"
                   result="webservice_resultHandler(event)"
                   fault="webservice_faultHandler(event)" />
    </fx:Declarations>

有没有办法让 FlashBuilder 响应为 JSON?

【问题讨论】:

  • contentType 声明数据将以何种格式发送,而不是您希望如何接收。使用URLRequest,您可以发送手动构造的请求标头,但AFAIK 您不能将URLRequests 与HTTPService 一起使用。对吗?
  • 您可以尝试按照这个问题中的讨论设置 Accept 标头:stackoverflow.com/questions/4196139/…

标签: xml web-services actionscript-3 apache-flex flash-builder


【解决方案1】:

这是 REST 服务吗?是春天吗?您也许可以在参数之前将“.xml”添加到 url 的末尾:

http://localhost/rest/users/byLastName.xml?lastName=Smith

如果是春天: 查看您的应用程序上下文中是否定义了 ContentNegotiatingViewResolver,以及其中定义了哪些媒体类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-09
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    • 2020-07-22
    相关资源
    最近更新 更多