使用方法 GET 可以使用 URLRequest/URLStream 自定义标头? [英] Custom headers possible with URLRequest/URLStream using method GET?

查看:32
本文介绍了使用方法 GET 可以使用 URLRequest/URLStream 自定义标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实很简单:

var req:URLRequest=new URLRequest();
req.url="http://somesite.com";
var header:URLRequestHeader=new URLRequestHeader("my-bespoke-header","1");
req.requestHeaders.push(header);
req.method=URLRequestMethod.GET;
stream.load(req);

但是,如果我使用 WireShark 检查流量,则不会发送 my-bespoke-header.如果我更改为 URLRequestMethod.POST 并将一些数据附加到 req.data,则发送标头,但接收应用程序需要 GET 而不是 POST.

Yet, if I inspect the traffic with WireShark, the my-bespoke-header is not being sent. If I change to URLRequestMethod.POST and append some data to req.data, then the header is sent, but the receiving application requires a GET not a POST.

文档中提到了一个不会被发送的头黑名单.my-bespoke-header 不是其中之一.可能值得一提的是,发起请求来自同一域上的不同端口.策略文件日志中没有报告任何内容,因此似乎不太可能,但是这是否可以通过强制加载带有 allow-http-request-headers-from 的 crossdomain.xml 来补救,尽管事实上这不是跨域问题吗?或者它只是 Flash Player 的一个未公开的功能,它只能通过 POST 请求发送自定义标头?

The documentation mentions a blacklist of headers that will not get sent. my-bespoke-header is not one of these. It's possibly worth mentioning that the originating request is from a different port on the same domain. Nothing is reported in the policyfile log, so it seems unlikely, but is this something that can be remedied by force loading a crossdomain.xml with a allow-http-request-headers-from despite the fact that this is not a crossdomain issue? Or is it simply an undocumented feature of the Flash Player that it can only send custom headers with a POST request?

推荐答案

据我所知,您对缺乏对 HTTP GET 的自定义标头支持的假设确实是一个未记录的功能(或错误?)标准库.

From what I can gather, it seems like your assumption about the lack of custom headers support for HTTP GET is indeed an undocumented feature (or a bug?) in the standard libraries.

无论如何,您可能想看看 as3httpclient 是否适合您的目的,然后让你解决了这个问题.这是开发人员博客中帖子的相关片段图书馆:

In any case, you might want to see if as3httpclient would fit your purposes and let you work around this issue. Here's a relevant snippet from a post in the blog of the developer of this library:

我无法设置一个HTTP/GET 请求.宏媒体闪存播放器仅允许您设置标题对于 POST 请求.我讨论过这个泰德帕特里克的问题,他告诉我我怎样才能用Socket来实现想要,他非常友善地给予我的代码片段,这让我开始了."

这篇关于使用方法 GET 可以使用 URLRequest/URLStream 自定义标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆