无法在 HTTPServiceWrapper 中设置 RequestHeaders (actionscript 3)
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于文档有点模糊,我会猜测一下。根据文档,
headers
是自定义标头的对象,因此向其传递索引数组可能不起作用。尝试传递一个已定义的对象: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: