<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FoxLing - 前端开发 &#187; HTTPService</title>
	<atom:link href="http://foxling.org/tag/httpservice/feed/" rel="self" type="application/rss+xml" />
	<link>http://foxling.org</link>
	<description>不积跬步 无以至千里</description>
	<lastBuildDate>Sat, 19 Nov 2011 16:29:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>AS3使用HTTPService类访问需要HTTP Basic Authentication认证的URL</title>
		<link>http://foxling.org/as-flex-air/as3-http-basic-authentication-with-httpservice-object/</link>
		<comments>http://foxling.org/as-flex-air/as3-http-basic-authentication-with-httpservice-object/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 15:29:11 +0000</pubDate>
		<dc:creator>FoxLing</dc:creator>
				<category><![CDATA[AS/Flex/AIR]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[HTTP-Basic-Authentication]]></category>
		<category><![CDATA[HTTPService]]></category>

		<guid isPermaLink="false">http://wp.foxling.cn/as-flex-air/http-basic-authentication-with-httpservice-object/</guid>
		<description><![CDATA[在使用API的时候，如嘀咕、Twitter、饭否的API，会需要使用用户名和密码登录，一般都是使用HTTP Basic Authentication认证，使用HTTPService类访问这种URL时，需要设置headers，用户名和密码的格式为“username:password”，并且需要Basic64加密，具体代码如下。 import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.utils.Base64Encoder; import mx.rpc.http.HTTPService; URLRequestDefaults.authenticate = false;//设默认为false，否则用户较验错误时会弹出验证框 private var result:XML; private function initApp():void { var base64enc:Base64Encoder = new Base64Encoder; base64enc.encode(&#34;user:password&#34;); //用户名和密码需要Base64编码 var user:String = base64enc.toString(); var http:HTTPService = new HTTPService; http.addEventListener(ResultEvent.RESULT,resultHandler);//监听返回事件 http.addEventListener(FaultEvent.FAULT,faultHandler); //监听失败事件 http.resultFormat = &#34;e4x&#34;;//返回格式 http.url = &#34;http://api.digu.com/statuses/friends_timeline.xml&#34;; 以嘀咕网的API为列 http.headers = {&#34;Authorization&#34;:&#34;Basic &#34; + user}; http.send(); } [...]]]></description>
			<content:encoded><![CDATA[<p>在使用API的时候，如嘀咕、Twitter、饭否的API，会需要使用用户名和密码登录，一般都是使用HTTP Basic Authentication认证，使用HTTPService类访问这种URL时，需要设置headers，用户名和密码的格式为“username:password”，并且需要Basic64加密，具体代码如下。</p>
<pre>
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.utils.Base64Encoder;
import mx.rpc.http.HTTPService;
URLRequestDefaults.authenticate = false;//设默认为false，否则用户较验错误时会弹出验证框

private var result:XML;
private function initApp():void
{
	var base64enc:Base64Encoder = new Base64Encoder;
	base64enc.encode(&#34;user:password&#34;); //用户名和密码需要Base64编码
	var user:String = base64enc.toString();

	var http:HTTPService = new HTTPService;
	http.addEventListener(ResultEvent.RESULT,resultHandler);//监听返回事件
	http.addEventListener(FaultEvent.FAULT,faultHandler);     //监听失败事件
	http.resultFormat = &#34;e4x&#34;;//返回格式
	http.url = &#34;http://api.digu.com/statuses/friends_timeline.xml&#34;; 以嘀咕网的API为列
	http.headers = {&#34;Authorization&#34;:&#34;Basic &#34; + user};
	http.send();
}
private function resultHandler(e:ResultEvent):void
{
	result = XML(e.result);
	test.dataProvider = result.status;//绑定数据
}
private function faultHandler(e:ResultEvent):void
{
	//处理失败
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://foxling.org/as-flex-air/as3-http-basic-authentication-with-httpservice-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

