无法在 HTTPServiceWrapper 中设置 RequestHeaders (actionscript 3)

发布于 2024-11-27 11:11:51 字数 1111 浏览 0 评论 0原文

我使用 Flash Builder 4 中的以数据为中心的开发功能创建了一个 HTTPService。出于某种原因,我无法为 HTTP GET 请求设置请求标头。我尝试为 mx.rpc.http.Operation 设置标头对象;但是,它似乎不起作用。数据包嗅探器显示请求标头未更改。

例如,这是 gettour 服务的一部分:

 public class GetTourService extends _Super_GetTourService
  {
     /**
     * Override super.init() to provide any initialization customization if needed.
     */
    protected override function preInitializeService():void
    {
      super.preInitializeService();
      // Initialization customization goes here

      var header:URLRequestHeader = new URLRequestHeader( "Accept", "application/json");
      var headers:Array = new Array();
      headers.push(header);

      var o:Object = this._serviceControl.getOperation( "gettour");
      var operation:Operation = o as Operation;
      operation.headers = headers;
    }
}

但是,数据包嗅探器将 Accept 标头显示为“Accept: /\r\n”。在 AIR 中,我遇到了类似的问题,即默认接受值的长列表,并且无法将接受值设置为“application/json”。我缺少什么?

非常感谢任何帮助。谢谢!

编辑:我今天早上找到了答案。而不是

headers.push( header);

我使用

headers[ "Accept"] = "/application/json";

这有效。

I created an HTTPService using the Data Centric Development feature in Flash Builder 4. For some reason, I'm not able to set the requestheaders for an HTTP GET request. I've tried setting the headers object for the mx.rpc.http.Operation; but, it doesn't seem to work. Packet sniffers show that the requestheader isn't changed.

For example here's part of the gettour service:

 public class GetTourService extends _Super_GetTourService
  {
     /**
     * Override super.init() to provide any initialization customization if needed.
     */
    protected override function preInitializeService():void
    {
      super.preInitializeService();
      // Initialization customization goes here

      var header:URLRequestHeader = new URLRequestHeader( "Accept", "application/json");
      var headers:Array = new Array();
      headers.push(header);

      var o:Object = this._serviceControl.getOperation( "gettour");
      var operation:Operation = o as Operation;
      operation.headers = headers;
    }
}

However, packet sniffers show the Accept header to be "Accept: /\r\n". In AIR I get a similar problem with the long list of default Accept values and can't set the Accept value to "application/json". What am I missing?

Any help is much appreciated. Thanks!

EDITED: I found the answer this morning. Instead of

headers.push( header);

I used

headers[ "Accept"] = "/application/json";

This worked.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏雪无痕 2024-12-04 11:11:51

由于文档有点模糊,我会猜测一下。根据文档,headers 是自定义标头的对象,因此向其传递索引数组可能不起作用。尝试传递一个已定义的对象:

operation.headers = {Accept:"application/json"};

Since the documentation for this is a bit vague I'm going to take a guess. According to the docs, headers is an Object of custom headers, so passing it an indexed array is probably not going to work. Try passing a defined Object instead:

operation.headers = {Accept:"application/json"};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文