2.7. HttpClient proxy configuration
Even though HttpClient is aware of complex routing scemes and proxy chaining, it supports only simple direct or one hop proxy connections out of the box.
The simplest way to tell HttpClient to connect to the target host via a proxy is by setting the default proxy parameter:
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpHost proxy = new HttpHost("someproxy", 8080);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
One can also instruct HttpClient to use the standard JRE proxy selector to obtain proxy information:
DefaultHttpClient httpclient = new DefaultHttpClient();
ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(
httpclient.getConnectionManager().getSchemeRegistry(),
ProxySelector.getDefault());
httpclient.setRoutePlanner(routePlanner);
Alternatively, one can provide a custom RoutePlanner implementation in order to have a complete control over the process of HTTP route computation:
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.setRoutePlanner(new HttpRoutePlanner() {
public HttpRoute determineRoute(
HttpHost target,
HttpRequest request,
HttpContext context) throws HttpException {
return new HttpRoute(target, null, new HttpHost("someproxy", 8080),
"https".equalsIgnoreCase(target.getSchemeName()));
}
});
@麥胖
呵呵,謝謝贊賞。
請(qǐng)把你修改后的代碼發(fā)到的郵箱 wellse@qq.com 我看下。
q@ice
請(qǐng)學(xué)習(xí)下Javascript的閉包特性,你就明白啦!
re: 我的書(shū)出版了 Web 2.0 技術(shù)資源 2010-04-28 10:22
恭喜,恭喜
謝謝樓上的兄弟! 對(duì)頭................. 的確存在那樣的問(wèn)題。
沒(méi)考慮周全。
re: 源碼分析:HashMap Web 2.0 技術(shù)資源 2008-08-27 11:37
#########################################
void transfer(Entry[] newTable) {
Entry[] src = table;
int newCapacity = newTable.length;
for (int j = 0; j < src.length; j++) {
Entry e = src[j];
if (e != null) {
src[j] = null;
do {
Entry next = e.next;
int i = indexFor(e.hash, newCapacity);
e.next = newTable[i];
newTable[i] = e;
e = next;
} while (e != null);
}
}
}
遍歷原來(lái)的數(shù)組,如果該Entry不是null的話(huà),說(shuō)明有映射,然后遍歷這個(gè)鏈表,把所有的映射插入到新的數(shù)組中,注意這里要從新計(jì)算索引位置。
#########################################
Entry next = e.next;
int i = indexFor(e.hash, newCapacity);
e.next = newTable[i]; ?????????
newTable[i] = e; ?????????
為什么 e.next 要指向自己呢?
@sly
報(bào)什么錯(cuò)啊........ 不得哦!
@js
設(shè)計(jì)這個(gè)Map 主要是為了填補(bǔ) Javascript 中沒(méi)有Map工具的不足。
你覺(jué)得你用Array 來(lái)代替 Map 那樣你寫(xiě)的Javascript 會(huì)清晰明了嗎?
那在Java里面何必需要HashSet, 直接用HashMap也能實(shí)現(xiàn)~
關(guān)鍵是讓自己編碼更清晰.... 數(shù)據(jù)類(lèi)型更明了。
做個(gè)服務(wù)層吧~
把業(yè)務(wù)邏輯集中到 Service
你應(yīng)該對(duì) collection 框架還不夠熟悉~ 加強(qiáng)下就OK了~
看錯(cuò)意圖了~ 這樣就OK了~
return new ArrayList( hs.values() );
頭都大了~~
// 將hashmap中value轉(zhuǎn)到list中
public static List getList(HashMap hs) {
List list = new ArrayList();
Iterator itr = hs.keySet().iterator();
while (itr.hasNext()) {
list.add(hs.get(itr.next()));
}
return list;
}
return new ArrayList( hs.keySet() );
就可以了撒,多麻煩的。
re: 關(guān)于java class loader的理解筆記 Web 2.0 技術(shù)資源 2007-04-11 14:27
好玩!!!!!!!!
re: 初始化有序常量的一點(diǎn)小技巧 Web 2.0 技術(shù)資源 2007-04-11 11:16
嘿嘿!~
莫名其妙.......... 不過(guò)還是辛苦了.
雖然使用正則表達(dá)式能很好的進(jìn)行字符串的解析、提取、替換,但是對(duì)于一些簡(jiǎn)單的應(yīng)用,使用 String 類(lèi)提供的一些方法就可以很好的完成,最突出的就是 split 方法。
和后面說(shuō)的矛盾了..........
Object is positioned relative to parent element's position—or to the body object if its parent element is not positioned—using the top and left properties.
查文檔才是王道!~
re: 歡迎加入成都java俱樂(lè)部 Web 2.0 技術(shù)資源 2006-11-30 20:02
BLOG ID: fantasy
QQ:8635335
期待加入ing .......
Javascript 也應(yīng)該面向?qū)ο笱絶 老大..........
re: 值得重視的Comparable接口 Web 2.0 技術(shù)資源 2006-11-03 21:41
策略模式.... 鑒定完畢......
re: 空(標(biāo)識(shí))接口的重要性 Web 2.0 技術(shù)資源 2006-10-29 14:36
經(jīng)典~! 很不錯(cuò)~~~
不幸的是..... 我還貼著菜鳥(niǎo)的標(biāo)簽.........
其實(shí)我已經(jīng)給你提供API了....... 可是你把他給改了....... 最可怕的是改錯(cuò)了
if (moz)
{
xmlDoc = document.implementation.createDocument("", "", null);
/*這里錯(cuò)大了!
readXML(xmlDoc);
*/
/*正確方式*/
xmlDoc.load( file );
xmlDoc.onload = function(){ readXML(xmlDoc); }
}
/********************* 代碼 ***********************/
<script language="javascript">
function importXML(file)
{
var xmlDoc=null;
var moz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument !='undefined');
var ie = (typeof window.ActiveXObject != 'undefined');
if (moz)
{
xmlDoc = document.implementation.createDocument("", "", null);
/*這里錯(cuò)大了!
readXML(xmlDoc);
*/
/*正確方式*/
xmlDoc.load( file );
xmlDoc.onload = function(){ readXML(xmlDoc); }
}
else if (ie)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.onreadystatechange = function()
{
if(xmlDoc.readyState == 4) readXML(xmlDoc);
}
xmlDoc.load(file);
}
}
function readXML( xmlDocObj )
{
var company = xmlDocObj.getElementsByTagName("company");
window.alert(company.length);
}
function doXML()
{
importXML("11.xml");
}
</script>
沒(méi)實(shí)現(xiàn) Visitor 和 Visitable 接口的 Visitor 模式.......
哈哈........ 感覺(jué)已經(jīng)變成簡(jiǎn)單的策略模式了........
實(shí)在不好意思......... 有點(diǎn)變味了.........
re: 您不得不關(guān)注的成長(zhǎng)群體 Web 2.0 技術(shù)資源 2006-10-25 22:57
"有志于實(shí)現(xiàn)四個(gè)現(xiàn)代化的青壯年"..............
哈哈哈!!!!!!!!!!
很有趣啊~ 可惜偶老了.............
俺是中國(guó)人........ 看不懂E文..........
不錯(cuò)! 總算看到另外一個(gè)版本的 外觀(guān)模式介紹了...........
感謝ing
估計(jì)是你加載 XML 的方式?jīng)]對(duì)。
請(qǐng)參考:
function loadXML(file)
{
var xml = null;
var ie = (typeof window.ActiveXObject != 'undefined');
var moz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined');
if (moz)
{
xml = document.implementation.createDocument("", "", null)
xml.load(file);
xml.onload = function ()
{
viewData(xml);
}
}
else if (ie)
{
xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.load(file);
if(xml.readyState == 4)
{
viewData(xml);
}
}
}
參考地址 :
http://bbs1.softhouse.com.cn/index.htm?url=/forum/help/user/index.jsp
修正了一個(gè)嚴(yán)重的BUG .
情況1
var array = new Array();
array.push("A"); array.length = 1
情況2 (想當(dāng)然的為初始化長(zhǎng)度,以為那樣效率可以高那么一點(diǎn)點(diǎn)........)
var array = new Array( 3 );
array.push("A"); array.length = 4
區(qū)別大呢............. 不像JAVA里面....
他爺爺?shù)膥~!
該 Pager 能使用于任何WEB容器。
關(guān)鍵是怎么使用他。
re: 按字節(jié)截取含雙字節(jié)的字符串! Web 2.0 技術(shù)資源 2006-10-13 21:12
效率太低了...........
給個(gè)簡(jiǎn)單的處理方式吧~~~
public static String getShorterString( String input , int bytes )
{
try
{
byte[] array = input.getBytes("GBK");
if( bytes >= array.length ) return input;
String result = new String(array , 0 , bytes ,"GBK");
return result.length() > 0 ? result : new String(array , 0 , bytes - 1 ,"GBK");
}
catch (UnsupportedEncodingException e)
{
return input;
}
}
re: 芒果軟件實(shí)驗(yàn)室 誠(chéng)攬人才 Web 2.0 技術(shù)資源 2006-09-11 17:46
拼命打撒~~~
打不過(guò)就撤退~~~~~~~~
沒(méi)的撤的地方了~~~ 就同志們就頂住!
@譚立平
謝謝 樓上的兄弟提出的BUG ~ 不過(guò)我自己測(cè)還沒(méi)測(cè)出這個(gè)問(wèn)題......
再次去參考了文檔 :
/***********************************************/
delete 運(yùn)算符
從對(duì)象中刪除一個(gè)屬性,或從數(shù)組中刪除一個(gè)元素。
delete expression
expression 參數(shù)是一個(gè)有效的 JScript 表達(dá)式,通常是一個(gè)屬性名或數(shù)組元素。
說(shuō)明
如果 expression 的結(jié)果是一個(gè)對(duì)象,且在 expression 中指定的屬性存在,而該對(duì)象又不允許它被刪除,則返回 false。
在所有其他情況下,返回 true。
/***********************************************/
在刪除元素的時(shí)候增加了~ this.containsKey(key) 的條件限制。
增加了 clear 方法。
re: 別忘了轉(zhuǎn)義\\ Web 2.0 技術(shù)資源 2006-05-30 15:21
啊........ 就怎么點(diǎn)啊...... 暈.....
@dennis
謝謝支持!
這個(gè)是在我上次寫(xiě)的HashMap上完全改進(jìn)的~~~
謝謝 bbs.51js.com 上的朋友提出寶貴的意見(jiàn)。
re: 防止任意形式的重復(fù)提交 Web 2.0 技術(shù)資源 2006-05-06 17:52
Struts 的 Token 機(jī)制可以解決這個(gè)問(wèn)題。
如果沒(méi)用Struts 怎么辦哇 .................. 郁悶。
/** key允許空值但hashcode方法卻沒(méi)有對(duì)其進(jìn)行空值檢查? **/
這個(gè)的確是問(wèn)題............. 但是我不想考慮太多的因素進(jìn)去......
我覺(jué)得那些應(yīng)該由用戶(hù)自己來(lái)檢查.....
否則會(huì)讓正個(gè)代碼變得很郁悶........... 郁悶拉。 55555555555
/**
resize要個(gè)_this參數(shù)干嘛用?
**/
是為了解決 用 var 定義的方法不能調(diào)用 this 方法... [私有不能訪(fǎng)問(wèn)公有方法]
所以得顯示的傳遞一個(gè) this 對(duì)象。
/**
if(++code > length){
code = 0;
}
干什么用?hashcode居然和length綁在一起,感覺(jué)很怪。。。
**/
因?yàn)槿绻?dāng)前位置發(fā)生沖突.......... 則向后查找.. 如果 > length 則 置0 。
re: 具有臭味的代碼 Web 2.0 技術(shù)資源 2006-03-24 09:34
暈~~~ 這臭味也太多拉......... 55555555555