开发者

Unable to set RequestHeaders in HTTPServiceWrapper (actionscript 3)

I created an HTTPService using the Data Centric Dev开发者_高级运维elopment 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.


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"};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜