难道闪光灯不支持用户名/密码的网址是什么?我有什么办法?不支持、闪光灯、有什么办法、用户名

由网友(旧容颜)分享简介:我一直在试图加载一些JSON从URL使用用户名/密码开头。因此​​,URL类似:的http://用户名:密码@ WWW。 myaddress.org.uk/api/profiles/ 我一直在使用,从greensock的的DataLoader类,它返回一个错误#2032:流错误如果认证了,但加载罚款当它是禁用的。我想...

我一直在试图加载一些JSON从URL使用用户名/密码开头。

因此​​,URL类似:的http://用户名:密码@ WWW。 myaddress.org.uk/api/profiles/

我一直在使用,从greensock的的DataLoader类,它返回一个错误#2032:流错误如果认证了,但加载罚款当它是禁用的。

我想加上'授权'的URLRequestHeader来克服这个问题?这是前进的最好方法是什么?

如果它是相关的,我正在开发使用的是FlashDevelop 4.0 /的Flex SDK 4.5.1的Windows 7企业版。

在此先感谢!

编辑:

我试图以类似的方式,这篇文章使用标题:Flex 3 - 如何支持HTTP认证的URLRequest ,但我并没有多大的成功?基于64位恩,我使用codeR就是从这里开始: HTTP ://jpauclair.net/2010/01/09/base64-optimized-as3-lib/

2日编辑:最新code

  _loader =新的DataLoader(端点,{的onComplete:handleComplete,onError的:handleError的,onFail:handleFail});

_loader.request.method = URLRequestMethod.POST;
_loader.request.data =新的URLVariables(需要= RandomData);

VAR字节:的ByteArray =新的ByteArray();
bytes.writeUTFBytes(USER +:+ PASS);
VAR headerString:字符串= Base64.en code(字节);
VAR标题:的URLRequestHeader =新URLRequestHeader('授权','基本'+ headerString);
_loader.request.requestHeaders.push(头);

_loader.load();
 

的crossdomain.xml

 < XML版本=1.0&GT?;
<!DOCTYPE跨域政策
  SYSTEMhttp://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<交域政策>
  <允许存取来自域=*/>
   <允许-HTTP请求报头,从域=*标题=授权/>
< /跨域策略>
 
为什么登陆到某个网站,会要求输入用户名和密码的

修改3 我也试着使用URLLoader:

  VAR的URLRequest:的URLRequest =新的URLRequest(终点);
urlRequest.method = URLRequestMethod.POST;
请将URLRequest.data =新的URLVariables(需要= RandomData);

VAR字节:的ByteArray =新的ByteArray();
bytes.writeUTFBytes(USER +:+ PASS);
VAR headerString:字符串= Base64.en code(字节);
VAR标题:的URLRequestHeader =新URLRequestHeader('授权','基本'+ headerString);
urlRequest.requestHeaders.push(头);

_urlLoader =新的URLLoader(的URLRequest);
_urlLoader.addEventListener(引发Event.COMPLETE,temp_handleComplete);
_urlLoader.addEventListener(IOErrorEvent.IO_ERROR,temp_handleError);
 

解决方案

基本身份验证是pretty的限制在Flash中,特别是如果你正在寻找消耗的API。我建议包装在您自己的服务器的请求,你可以实现一个基于会话的或基于密钥的认证。

例如。 http://api.your-domain.co.uk/api/型材/键= 0123456789abdef 将调用服务器端脚本的API密钥的有效性1)检查,2)的 HTTP://用户名:password@www.myaddress.org.uk/api/profiles/ 并返回

如果你正在使用超过/ API /型材/出来的API,我建议你写一个重写,将接受任何路径,并获取相应的远程路径。该脚本可以是任何支持您的服务器上,从PHP脚本到bash脚本。

或者如果你的服务器应用程序支持的话,你甚至可以使用类似的mod_proxy用于建立的反向代理的。其实,现在我想想,使用Apache或Lighttpd的反向代理可能是最简单的解决方案! (参见: http://httpd.apache.org/docs/2.0/mod/ mod_proxy.html )

I've been trying to load some JSON from a URL with a username/password at the beginning.

So the URL resembles: http://username:password@www.myaddress.org.uk/api/profiles/

I've been using the DataLoader class from greensock and it returns a Error #2032: Stream Error if the authentication is up but loads fine when it is disabled.

I'm trying to add a 'Authorization' URLRequestHeader to get round this issue? Is this the best way forward?

If it is relevant, I'm developing using FlashDevelop 4.0 / Flex SDK 4.5.1 on Windows 7 Enterprise.

Thanks in advance!

Edit:

I'm trying to use headers in a similar way to this post: Flex 3 - how to support HTTP Authentication URLRequest? but I'm not having much success. The base64 encoder I'm using is from here: http://jpauclair.net/2010/01/09/base64-optimized-as3-lib/

2nd Edit: latest code

_loader = new DataLoader(ENDPOINT, { onComplete:handleComplete, onError:handleError, onFail:handleFail } );

_loader.request.method = URLRequestMethod.POST;
_loader.request.data = new URLVariables("required=RandomData");

var bytes:ByteArray = new ByteArray();
bytes.writeUTFBytes(USER+':'+PASS);
var headerString:String = Base64.encode(bytes);
var header:URLRequestHeader = new URLRequestHeader('Authorization', 'Basic ' + headerString );
_loader.request.requestHeaders.push(header);

_loader.load();

crossdomain.xml

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy 
  SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <allow-access-from domain="*" />
   <allow-http-request-headers-from domain="*" headers="Authorization" />
</cross-domain-policy>

Edit 3 I've also tried using a URLLoader:

var urlRequest:URLRequest = new URLRequest(ENDPOINT);
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = new URLVariables("required=RandomData");

var bytes:ByteArray = new ByteArray();
bytes.writeUTFBytes(USER+':'+PASS);
var headerString:String = Base64.encode(bytes);
var header:URLRequestHeader = new URLRequestHeader('Authorization', 'Basic ' + headerString );
urlRequest.requestHeaders.push(header);

_urlLoader = new URLLoader(urlRequest);
_urlLoader.addEventListener(Event.COMPLETE, temp_handleComplete);
_urlLoader.addEventListener(IOErrorEvent.IO_ERROR, temp_handleError);

解决方案

Basic Authentication is pretty restricted in Flash, especially if you're looking to consume an API. I would suggest wrapping the request at your own server where you could implement a session-based or key-based authentication.

Eg. http://api.your-domain.co.uk/api/profiles/?key=0123456789abdef would invoke a server-side script that 1) checks for the validity of the API key and 2) fetches data from http://username:password@www.myaddress.org.uk/api/profiles/ and returns it.

If you're using more than the "/api/profiles/" out of the API, I suggest writing a rewrite that would accept any path and fetch the corresponding remote path. The script can be anything that is supported on your server, from a php script to a bash script.

Or if your server application supports it you may even use something like mod_proxy for setting up a Reverse Proxy. Actually, now that I think about it, a reverse proxy using Apache or Lighttpd might be the easiest of the solutions! (See: http://httpd.apache.org/docs/2.0/mod/mod_proxy.html)

阅读全文

相关推荐

最新文章