锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久久亚洲AV成人无码网站,在线观看亚洲AV日韩A∨,欧洲亚洲综合一区二区三区 http://www.tkk7.com/guangnian0412/category/9444.htmlJava in my lifezh-cnTue, 27 Feb 2007 10:25:00 GMTTue, 27 Feb 2007 10:25:00 GMT60[Commons Logging]浣跨敤涓涓娊璞$殑Logging鎺ュ彛錛團rom Jarkata Commons Cookbook 7.10錛?/title><link>http://www.tkk7.com/guangnian0412/archive/2006/04/24/42874.html</link><dc:creator>guangnian</dc:creator><author>guangnian</author><pubDate>Mon, 24 Apr 2006 10:32:00 GMT</pubDate><guid>http://www.tkk7.com/guangnian0412/archive/2006/04/24/42874.html</guid><wfw:comment>http://www.tkk7.com/guangnian0412/comments/42874.html</wfw:comment><comments>http://www.tkk7.com/guangnian0412/archive/2006/04/24/42874.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/guangnian0412/comments/commentRss/42874.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/guangnian0412/services/trackbacks/42874.html</trackback:ping><description><![CDATA[ <font face="Georgia">聽聽 錛圝arkata 鐨?Commons Logging 鍖呯幇鍦ㄥ凡緇忚鐢ㄥ湪鍑犱箮鎵鏈夌殑寮婧愰」鐩箣涓紝瀹冨彲浠ヤ嬌浣犲紑鍙戠殑緋葷粺宸ヤ綔鍦ㄤ笉鍚岀殑鏃ュ織妗嗘灦涓嬶紝鍖呮嫭Sun鐨刲ogging妗嗘灦鍜孉pache Log4j銆傜幇鍦–ommons Logging + Apache Log4j 鐨勮韓褰辨槸闅忓鍙錛孋ommons Logging 鐨勬槗鐢ㄤ笌Log4j鐨勫己澶у姛鑳藉艦鎴愪簡緇濋厤銆傦級<br /><br />闂錛?br />聽聽聽 聽 浣犳鍦ㄥ啓涓涓彲閲嶇敤鐨勪唬鐮佸簱錛岃屼綘涓嶇煡閬撲綘鐨勪唬鐮佸湪鍝噷騫朵笖鏄浣曞伐浣滅殑銆備綘闇瑕佷竴涓娊璞$殑鏃ュ織鎺ュ彛鏉ュ啓鍏ユ棩蹇椾俊鎭紝鍥犱負浣犱笉鑳界‘瀹歀og4j鎴栬呮槸JDK 1.4 logging鐨勫瓨鍦ㄦс?br /><br />瑙e喅錛?br />聽聽聽聽聽聽聽 閫氳繃Jakarta Commons Logging 鐨凩og 鎺ュ彛鏉ヨ褰曚俊鎭紝鐒跺悗渚濋潬Commons Logging鑷韓鏉ュ喅瀹氬湪榪愯鏃朵嬌鐢ㄥ摢縐嶅叿浣撶殑鏃ュ織妗嗘灦銆備笅闈㈢殑浠g爜浣跨敤浜哃og鎺ュ彛鏉ヨ褰晅race錛宒ebug錛宨nfo錛寃arning錛宔rror鍜宖atal淇℃伅錛?br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);">聽1</span>聽<span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽org.apache.commons.logging.LogFactory;<br /></span><span style="color: rgb(0, 128, 128);">聽2</span>聽<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽org.apache.commons.logging.Log<br /></span><span style="color: rgb(0, 128, 128);">聽3</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">聽4</span>聽<span style="color: rgb(0, 0, 0);">Log聽log聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽LogFactory.getLog(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">com.discursive.jccook.SomeApp</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽);聽<br /></span><span style="color: rgb(0, 128, 128);">聽5</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">聽6</span>聽<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(聽log.isTraceEnabled(聽)聽)聽{<br /></span><span style="color: rgb(0, 128, 128);">聽7</span>聽<span style="color: rgb(0, 0, 0);">聽聽聽聽log.trace(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">This聽is聽a聽trace聽message</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽);<br /></span><span style="color: rgb(0, 128, 128);">聽8</span>聽<span style="color: rgb(0, 0, 0);">}<br /></span><span style="color: rgb(0, 128, 128);">聽9</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</span>聽<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(聽log.isDebugEnabled(聽)聽)聽{<br /></span><span style="color: rgb(0, 128, 128);">11</span>聽<span style="color: rgb(0, 0, 0);">聽聽聽聽log.debug(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">This聽is聽a聽debug聽message</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽);<br /></span><span style="color: rgb(0, 128, 128);">12</span>聽<span style="color: rgb(0, 0, 0);">}<br /></span><span style="color: rgb(0, 128, 128);">13</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">14</span>聽<span style="color: rgb(0, 0, 0);">log.info(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">This聽is聽an聽informational聽message</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽);<br /></span><span style="color: rgb(0, 128, 128);">15</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">16</span>聽<span style="color: rgb(0, 0, 0);">log.warn(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">This聽is聽a聽warning</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽);<br /></span><span style="color: rgb(0, 128, 128);">17</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">18</span>聽<span style="color: rgb(0, 0, 0);">log.error(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">This聽is聽an聽error</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽);<br /></span><span style="color: rgb(0, 128, 128);">19</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">20</span>聽<span style="color: rgb(0, 0, 0);">log.fatal(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">This聽is聽fatal</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽);</span></div>聽聽聽聽聽 LogFactory.getInstance() 榪斿洖涓涓狶og鎺ュ彛鐨勫叿浣撳疄鐜幫紝榪欎釜瀹炵幇涓庡簳灞傚叿浣撶殑鏃ュ織妗嗘灦鐩稿搴斻備緥濡傦紝濡傛灉浣犵殑緋葷粺鏄嬌鐢ˋpache Log4j 錛屼竴涓狶og4JLogger灝嗚榪斿洖錛屽搴斾簬Log4J category </font> <font> <font face="Georgia"> <span style="color: rgb(0, 0, 0);"> </span> <span style="color: rgb(0, 0, 0);">com.discursive.jccook.SomeApp 銆?br /><br />璁ㄨ錛?br />聽聽聽聽聽聽聽 涓涓彲閲嶇敤浠g爜搴撶殑寮鍙戣呬笉鑳介鐭ュ叾浠g爜搴撳皢鍦ㄤ綍鏃朵綍鍦拌鐢ㄥ埌錛岃岀幇鍦ㄦ湁寰堝鐨勬棩蹇楁鏋跺彲浠ヤ嬌鐢紝鎵浠ュ綋寮鍙戝彲閲嶇敤浠g爜搴撶殑鏃跺欙紝浣跨敤Commons Logging 鏄潪甯告槑鏅虹殑錛屼緥濡侸akarta Commons 緇勪歡銆傚綋璋冪敤LogFactory.getInstance()鏂規硶鐨勬椂鍊欙紝Commons Logging 灝嗛氳繃緋葷粺灞炴у拰classpath涓殑綾誨簱鏉ュ喅瀹氬拰綆$悊閫傚綋鐨勬棩蹇楁鏋躲傚浜庝竴涓皬鍨嬪彲閲嶇敤緇勪歡鐨勫紑鍙戣呮潵璇達紝榪涜鏃ュ織璁板綍鍙渶瑕佽皟鐢↙og鎺ュ彛銆傝岄厤緗簳灞傛棩蹇楁鏋剁殑璐熸媴錛屽氨杞Щ鍒頒嬌鐢ㄥ叾緇勪歡搴撶殑寮鍙戣呰韓涓娿?br /><br />鍙傝冿細<br />聽聽聽聽聽聽聽 7.11鑺傝緇嗙殑璇存槑浜咰ommons Logging鍦ㄨ繍琛屾椂紜畾閫傚綋鏃ュ織妗嗘灦鐨勭畻娉曘?br /><br /></span> </font> </font> <font face="Georgia">聽聽聽聽 <br /></font> <img src ="http://www.tkk7.com/guangnian0412/aggbug/42874.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/guangnian0412/" target="_blank">guangnian</a> 2006-04-24 18:32 <a href="http://www.tkk7.com/guangnian0412/archive/2006/04/24/42874.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>[HttpClient] 鍒涘緩涓涓狧TTP POST 璇鋒眰 (from Jakarta Commons cookbook 11.7 )http://www.tkk7.com/guangnian0412/archive/2006/04/11/40529.htmlguangnianguangnianTue, 11 Apr 2006 14:41:00 GMThttp://www.tkk7.com/guangnian0412/archive/2006/04/11/40529.htmlhttp://www.tkk7.com/guangnian0412/comments/40529.htmlhttp://www.tkk7.com/guangnian0412/archive/2006/04/11/40529.html#Feedback2http://www.tkk7.com/guangnian0412/comments/commentRss/40529.htmlhttp://www.tkk7.com/guangnian0412/services/trackbacks/40529.html闂錛?br />聽聽聽聽聽聽聽 浣犻渶瑕佷嬌鐢℉TTP POST 鏂規硶鏉ュ悜涓涓猻ervlet浼犻掑弬鏁般?br />
璁ㄨ錛?br />聽聽聽聽聽聽聽 鍒涘緩涓涓?PostMethod 瀵硅薄錛岀劧鍚庤皟鐢?setParameter() 鎴?addParameter() 鏂規硶璁劇疆鍙傛暟銆?PostMethod 瀵硅薄灝嗕細浼犻佷竴涓?Content-Type 澶翠負 application/x-www-form-urlencoded 鐨勮姹傦紝騫朵笖鍙傛暟灝嗗湪璇鋒眰body涓浼犻併傚湪涓嬪垪鐨勪緥瀛愪腑婕旂ず浜嗙敤 PostMethod 瀵硅薄浼犻掑弬鏁扮殑鐢ㄦ硶錛?br />
import聽org.apache.commons.httpclient.HttpClient;
import聽org.apache.commons.httpclient.HttpException;
import聽org.apache.commons.httpclient.NameValuePair;
import聽org.apache.commons.httpclient.methods.PostMethod;

HttpClient聽client聽
=new聽HttpClient(聽);

//聽Create聽POST聽method
String聽url聽="http://www.discursive.com/cgi-bin/jccook/param_list.cgi";
PostMethod聽method聽
=new聽PostMethod(聽url聽);

//聽Set聽parameters聽on聽POST聽聽聽聽
method.setParameter(聽"test1",聽"Hello聽World"聽);
method.addParameter(聽
"test2",聽"This聽is聽a聽Form聽Submission"聽);
method.addParameter(聽
"Blah",聽"Whoop"聽);
method.addParameter(聽
new聽NameValuePair(聽"Blah",聽"Whoop2"聽)聽);

//聽Execute聽and聽print聽response
client.executeMethod(聽method聽);
String聽response聽
=聽method.getResponseBodyAsString(聽);
System.out.println(聽response聽);

method.releaseConnection(聽);
聽聽聽聽聽聽 param_list.cgi CGI鑴氭湰浼氬鎵浠ユ帴鏀跺埌鐨勫弬鏁拌繘琛屽洖鏄撅紝浠庝笅闈㈢殑杈撳嚭涓紝浣犲彲浠ョ湅鍒頒紶閫掔粰CGI鑴氭湰鐨勪笁涓弬鏁幫細
These聽are聽the聽parameters聽I聽received:

test1:
聽聽Hello聽World
test2:
聽聽This聽is聽a聽Form聽Submission
Blah:
聽聽Whoop
聽聽Whoop2
聽聽聽聽聽聽 鏈夊嚑縐嶆柟娉曟潵鍦ㄤ竴涓狿ostMethod瀵硅薄涓緗弬鏁般傛渶鐩存帴鐨勬柟娉曞氨鏄皟鐢╯etParameter()鏂規硶錛屽茍浼犻掍袱涓瓧絎︿覆緇欏畠錛氬弬鏁扮殑鍚嶇О鍜屽弬鏁板箋俿etParameter()鏂規硶灝嗕細鏇夸唬浠諱綍宸茬粡瀛樺湪鐨勫悓鍚嶅弬鏁般備絾鏄紝濡傛灉涓涓悓鍚嶇殑鍙傛暟宸茬粡瀛樺湪涓涓狿ostMethod瀵硅薄涓紝addParameter()灝嗕細鍔犲叆鍙︿竴涓悓鍚嶅弬鏁板鹼紱addParameter()鏂規硶鍚屾牱鎺ュ彈涓や釜String錛氬弬鏁板悕鍜屽弬鏁板箋傚彟涓縐嶆柟娉曪紝榪欎袱涓柟娉曞悓鏍鋒帴鍙椾竴涓寘瑁呬簡鍙傛暟鍚嶅拰鍙傛暟鍊肩殑NameValuePair瀵硅薄銆傚湪鍓嶉潰鐨勪緥瀛愪腑錛岄氳繃addParameter()鏂規硶錛岀敤鍙傛暟鍚岯lah浼犻掍簡涓や釜鍊鹼紝絎竴嬈$敤涓や釜String浣滀負鍙傛暟錛岀浜屾鐢ㄤ竴涓狽ameValuePair瀵硅薄浣滀負鍙傛暟銆?br />


guangnian 2006-04-11 22:41 鍙戣〃璇勮
]]>
[HttpClient] 鍦ㄦ煡璇㈠瓧絎︿覆涓紶閫佸弬鏁?錛坒rom Jakarta Commons Cookbook 11銆?錛?/title><link>http://www.tkk7.com/guangnian0412/archive/2006/04/04/39235.html</link><dc:creator>guangnian</dc:creator><author>guangnian</author><pubDate>Tue, 04 Apr 2006 11:19:00 GMT</pubDate><guid>http://www.tkk7.com/guangnian0412/archive/2006/04/04/39235.html</guid><wfw:comment>http://www.tkk7.com/guangnian0412/comments/39235.html</wfw:comment><comments>http://www.tkk7.com/guangnian0412/archive/2006/04/04/39235.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/guangnian0412/comments/commentRss/39235.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/guangnian0412/services/trackbacks/39235.html</trackback:ping><description><![CDATA[ <font face="Georgia">闂錛?br />聽聽聽聽聽聽聽 浣犻渶瑕佸湪涓涓猆RL涓紶閫佹煡璇㈠弬鏁般?br /><br />瑙g瓟錛?br />聽聽聽聽聽聽聽 浣跨敤涓涓狧ttpMethod瀹炰緥鐨剆etQueryString()鏂規硶鏉ヨ緗煡璇㈠瓧絎︿覆銆備嬌鐢║RIUtil綾誨鍖呭惈鍦║RL涓殑鏂囨湰榪涜緙栫爜銆備笅闈㈢殑渚嬪瓙鍦ㄦ煡璇㈠瓧絎︿覆涓斁鍏ヤ簡涓や釜鍙傛暟錛?br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);">聽1</span>聽<span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽org.apache.commons.httpclient.HttpClient;<br /></span><span style="color: rgb(0, 128, 128);">聽2</span>聽<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽org.apache.commons.httpclient.HttpException;<br /></span><span style="color: rgb(0, 128, 128);">聽3</span>聽<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽org.apache.commons.httpclient.HttpMethod;<br /></span><span style="color: rgb(0, 128, 128);">聽4</span>聽<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽org.apache.commons.httpclient.NameValuePair;<br /></span><span style="color: rgb(0, 128, 128);">聽5</span>聽<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽org.apache.commons.httpclient.methods.GetMethod;<br /></span><span style="color: rgb(0, 128, 128);">聽6</span>聽<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽org.apache.commons.httpclient.util.URIUtil;<br /></span><span style="color: rgb(0, 128, 128);">聽7</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">聽8</span>聽<span style="color: rgb(0, 0, 0);">HttpClient聽client聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽HttpClient(聽);<br /></span><span style="color: rgb(0, 128, 128);">聽9</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</span>聽<span style="color: rgb(0, 0, 0);">String聽url聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://www.discursive.com/cgi-bin/jccook/param_list.cgi</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);">11</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">12</span>聽<span style="color: rgb(0, 0, 0);">HttpMethod聽method聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽GetMethod(聽url聽);<br /></span><span style="color: rgb(0, 128, 128);">13</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">14</span>聽<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 鐢╯etQueryString()鏉ヨ緗煡璇㈠瓧絎︿覆</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">15</span>聽<b><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">method.setQueryString(URIUtil.encodeQuery(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">test1=O聽Reilly&blah=Whoop</span><span style="color: rgb(0, 0, 0);">"</span></b><span style="color: rgb(0, 0, 0);"><b>));</b><br /></span><span style="color: rgb(0, 128, 128);">16</span>聽<span style="color: rgb(0, 0, 0);">System.out.println(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">With聽Query聽String:聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">聽method.getURI(聽)聽);<br /></span><span style="color: rgb(0, 128, 128);">17</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">18</span>聽<span style="color: rgb(0, 0, 0);">client.executeMethod(聽method聽);<br /></span><span style="color: rgb(0, 128, 128);">19</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">20</span>聽<span style="color: rgb(0, 0, 0);">System.out.println(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Response:\n聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">聽method.getResponseBodyAsString(聽)聽);<br /></span><span style="color: rgb(0, 128, 128);">21</span>聽<span style="color: rgb(0, 0, 0);">method.releaseConnection(聽);</span></div>聽聽聽聽聽聽 </font> <font> <font face="Georgia"> <span style="color: rgb(0, 0, 0);">param_list.cgi聽 CGI鑴氭湰鍙槸綆鍗曠殑鍥炴樉鎺ユ敹鍒扮殑鎵浠ュ弬鏁幫紝鍦ㄤ笅闈㈢殑杈撳嚭涓紝浣犲彲浠ョ湅鍒癠RIUtil濡備綍瀵圭涓涓弬鏁拌繘琛岀紪鐮侊細<br />聽聽聽聽聽聽 <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">With聽Query聽String:聽http:</span><span>//www.discursive.com/cgi-bin/jccook/param_list.</span><span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">cgi</span><b><span style="color: rgb(0, 0, 0);">?</span></b><span style="color: rgb(0, 0, 0);">test1</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">O</span><span style="color: rgb(0, 0, 0);">%</span><span style="color: rgb(0, 0, 0);">20Reilly</span><span style="color: rgb(0, 0, 0);">&</span><span style="color: rgb(0, 0, 0);">blah</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">Whoop<br />Response:<br />聽These聽are聽the聽parameters聽I聽received:<br /><br />test1:<br />聽聽O聽Reilly<br />blah:<br />聽聽Whoop<br /></span></div>聽聽聽聽聽 鎻愮ず錛氫綘涓嶅繀鍦╯etQueryString()鏂規硶涓姞鍏ワ紵鍙鳳紝褰揌ttpClient瀹炰緥鎵цexecuteMethod()鏂規硶鏃訛紝瀹冧細琚嚜鍔ㄥ姞鍏ャ?br /><br />璁ㄨ錛?br />聽聽聽聽聽 聽聽 鍦ㄥ墠闈㈢殑渚嬪瓙涓紝HttpMethod鐨剆etQueryString()鏂規硶鏄竴嬈℃у皢鏁翠釜鏌ヨ瀛楃涓插姞榪涘幓錛屼絾鏄繕鏈夊彟澶栦竴縐嶉夋嫨錛氶氳繃涓涓狽ameValuePair瀵硅薄鐨勬暟緇勬潵璁劇疆鏌ヨ瀛楃涓層傚綋涓涓狽ameValuePair[]浼犲叆setQueryString()鏂規硶涓椂錛孒ttpMethod瀹炰緥浼氫粠鏁扮粍涓彇鍑烘瘡涓涓狽ameValuePair瀵硅薄錛岀劧鍚庡垱寤轟竴緋誨垪鐢?amp;鍙峰垎鍓茬殑鍙傛暟銆傝繖縐嶆柟娉曚嬌紼嬪簭浠g爜鏇村姞騫插噣錛屽洜涓轟綘涓嶅繀榪炴帴瀛楃涓叉潵浼犻掑涓弬鏁般備笅闈㈢殑渚嬪瓙鐢∟ameValuePair瀵硅薄錛屼笌鍓嶄竴涓緥瀛愯緗簡鍚屾牱鐨勫弬鏁幫細<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);">聽1</span>聽<span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 鐢∟ameValuePair瀵硅薄璁劇疆鏌ヨ鍙傛暟</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">聽2</span>聽<span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">HttpMethod聽method聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽GetMethod(聽url聽);<br /></span><span style="color: rgb(0, 128, 128);">聽3</span>聽<span style="color: rgb(0, 0, 0);">NameValuePair聽pair聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 128, 128);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽NameValuePair(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">test1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,聽URIUtil.encodeQuery(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">O聽Reilly</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽)聽);<br /></span><span style="color: rgb(0, 128, 128);">聽4</span><span style="color: rgb(0, 0, 0);">NameValuePair聽pair2聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 128, 128);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽NameValuePair(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">blah</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,聽URIUtil.encodeQuery(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Whoop</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽)聽);<br /></span><span style="color: rgb(0, 128, 128);">聽5</span><span style="color: rgb(0, 0, 0);">NameValuePair[]聽pairs聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽NameValuePair[]聽{聽pair,聽pair2聽};<br /></span><span style="color: rgb(0, 128, 128);">聽6</span><span style="color: rgb(0, 0, 0);">method.setQueryString(聽pairs聽);<br /></span><span style="color: rgb(0, 128, 128);">聽7</span><span style="color: rgb(0, 0, 0);">System.out.println(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">With聽NameValuePairs:聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">聽method.getURI(聽)聽);<br /></span><span style="color: rgb(0, 128, 128);">聽8</span><span style="color: rgb(0, 0, 0);">client.executeMethod(聽method聽);<br /></span><span style="color: rgb(0, 128, 128);">聽9</span><span style="color: rgb(0, 0, 0);"> System.out.println(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Response:\n聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">聽method.getResponseBodyAsString(聽)聽);<br /></span><span style="color: rgb(0, 128, 128);">聽10</span><span style="color: rgb(0, 0, 0);">method.releaseConnection(聽);</span></div>聽聽聽聽聽聽聽 鏍規嵁RFC1738錛孶RL鍙兘澶熷寘鍚瓧姣嶅拰鏁板瓧瀛楃錛歔0-9,a-z,A-Z]鍜屼竴浜涚壒孌婂瓧絎︺傚鏋滀綘闇瑕佸湪鍙傛暟涓紶閫佷竴浜沀RL鎵涓嶅厑璁哥殑瀛楃錛屼綘灝遍渶瑕佸浣犵殑瀛楃涓茶繘琛岀紪鐮侊紝浠ョ鍚圧FC1738鐨勮瀹氥俇RIUtil綾繪湁涓涓柟娉昬ncodeQuery()鑳藉瀵瑰墠闈緥瀛愪腑鐨?O Reilly"榪涜緙栫爜銆備笅闈㈢殑浠g爜灞曠ず浜嗙敤URIUtil綾繪潵瀵瑰寘鍚湪URL涓殑瀛楃涓茶繘琛岀紪鐮侊細<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);">1</span>聽<span style="color: rgb(0, 0, 0);">String聽encoded1聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽URIUtil.encodeQuery(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><test>=O'Connell</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽);<br /></span><span style="color: rgb(0, 128, 128);">2</span>聽<span style="color: rgb(0, 0, 0);">String聽encoded2聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽URIUtil.encodeQuery(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">one:two=thr聽ee#</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽);<br /></span><span style="color: rgb(0, 128, 128);">3</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">4</span>聽<span style="color: rgb(0, 0, 0);">String聽decoded聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽URIUtil.decode(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Hello%20World%3F</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽);<br /></span><span style="color: rgb(0, 128, 128);">5</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">6</span>聽<span style="color: rgb(0, 0, 0);">System.out.println(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Encoded:聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">聽encoded1聽);<br /></span><span style="color: rgb(0, 128, 128);">7</span>聽<span style="color: rgb(0, 0, 0);">System.out.println(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Encoded:聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">聽encoded2聽);<br /></span><span style="color: rgb(0, 128, 128);">8</span>聽<span style="color: rgb(0, 0, 0);">System.out.println(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Decoded:聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">聽decoded聽);</span></div><br />聽聽聽聽聽聽聽 榪欎釜綆鍗曠殑渚嬪瓙鐢║RIUtil綾誨涓や釜瀛楃涓茶繘琛屼簡緙栫爜錛屽茍瀵逛竴涓粡榪囩紪鐮佺殑瀛楃涓茶繘琛岃В鐮併備笅闈㈢殑杈撳嚭灞曠ず浜嗘瘡涓漿鎹㈢殑緇撴灉錛?br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">Encoded:聽</span><span style="color: rgb(0, 0, 0);">%</span><span style="color: rgb(0, 0, 0);">3ctest</span><span style="color: rgb(0, 0, 0);">%</span><span style="color: rgb(0, 0, 0);">e3</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">O</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">Connell</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);">Encoded:聽one</span><span style="color: rgb(0, 0, 0);">%</span><span style="color: rgb(0, 0, 0);">3atwo</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">thr</span><span style="color: rgb(0, 0, 0);">%</span><span style="color: rgb(0, 0, 0);">20ee#</span><span style="color: rgb(0, 0, 0);">23</span><span style="color: rgb(0, 0, 0);"><br />Decoded:聽Hello聽World</span><span style="color: rgb(0, 0, 0);">?</span></div>聽聽聽聽聽聽聽聽 <br />鍙傝冿細<br />聽聽聽聽聽聽聽 鍦ㄨ繖涓緥瀛愪腑錛孶RLUtil瀵逛紶鍏ョ殑鏌ヨ瀛楃涓茬殑鍐呭榪涜浜嗙紪鐮併傛渶榪戯紝HttpClient灝忕粍灝嗕竴浜沀RL緙栫爜鍜岃В鐮佺殑閫昏緫浠g爜縐誨叆浜咼akarta Commons Codec欏圭洰涓紝瀵瑰簲鐨勭被鍚嶄負URLCodec銆傞渶瑕乁RLCodec鏇村鐨勪俊鎭紝璇峰弬鑰?/span> </font> </font> <font> <font face="Georgia"> <span style="color: rgb(0, 0, 0);">Jakarta Commons Codec欏圭洰涓婚〉錛坔ttp://jakarta.apache.org/codec錛夈?/span> </font> </font> <br /> <font> <font face="Georgia"> <span style="color: rgb(0, 0, 0);">聽聽聽聽聽聽聽聽 RFC1738璁ㄨ浜哢RL涓殑鍚堟硶瀛楃錛屽茍瑙勫畾浜嗗鍏朵粬瀛楃榪涜緙栫爜鐨勮繃紼嬨俁FC1738鑳藉鍦╤ttp:// www.zvon.org/tmRFC/RFC2616/Output/index.html涓壘鍒般?</span> <span style="color: rgb(0, 0, 0);"> </span> </font> </font> <img src ="http://www.tkk7.com/guangnian0412/aggbug/39235.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/guangnian0412/" target="_blank">guangnian</a> 2006-04-04 19:19 <a href="http://www.tkk7.com/guangnian0412/archive/2006/04/04/39235.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>[HttpClient] 鎵цHTTP GET鏂規硶 錛坒rom Jakarta Commons Cookbook 11銆?錛?/title><link>http://www.tkk7.com/guangnian0412/archive/2006/04/04/39044.html</link><dc:creator>guangnian</dc:creator><author>guangnian</author><pubDate>Mon, 03 Apr 2006 16:18:00 GMT</pubDate><guid>http://www.tkk7.com/guangnian0412/archive/2006/04/04/39044.html</guid><wfw:comment>http://www.tkk7.com/guangnian0412/comments/39044.html</wfw:comment><comments>http://www.tkk7.com/guangnian0412/archive/2006/04/04/39044.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/guangnian0412/comments/commentRss/39044.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/guangnian0412/services/trackbacks/39044.html</trackback:ping><description><![CDATA[ <font face="Georgia">闂錛?br />聽聽聽聽聽聽聽 浣犻渶瑕侀氳繃HTTP GET鏂規硶鏉ヨ幏鍙栦俊鎭?br /><br />瑙g瓟錛?br />聽聽聽聽聽聽聽 鍒涘緩涓涓狧ttpClient瀹炰緥錛屽茍璋冪敤浠etMethod瀵硅薄涓哄弬鏁扮殑executeMethod鏂規硶銆傜劧鍚庯紝鍝嶅簲鐨勫唴瀹瑰氨鍙互閫氳繃涓涓狪nputStream錛宐yte[]錛屾垨鑰呮槸String鏉ヨ幏寰椼備笅闈㈢殑渚嬪瓙灝嗚幏寰? <a >http://www.discursive.com /jccook/</a>鐨勫唴瀹癸紝騫朵笖浠ヤ竴涓猄tring鏉ヨ幏寰楀搷搴斻?br />聽聽聽聽聽聽聽 <div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);">聽1</span>聽<span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽org.apache.commons.httpclient.HttpClient;<br /></span><span style="color: rgb(0, 128, 128);">聽2</span>聽<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽org.apache.commons.httpclient.HttpException;<br /></span><span style="color: rgb(0, 128, 128);">聽3</span>聽<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽org.apache.commons.httpclient.HttpMethod;<br /></span><span style="color: rgb(0, 128, 128);">聽4</span>聽<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽org.apache.commons.httpclient.methods.GetMethod;<br /></span><span style="color: rgb(0, 128, 128);">聽5</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">聽6</span>聽<span style="color: rgb(0, 0, 0);">HttpClient聽client聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽HttpClient(聽);<br /></span><span style="color: rgb(0, 128, 128);">聽7</span>聽<span style="color: rgb(0, 0, 0);">String聽url聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">http://www.discursive.com/jccook/</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);">聽8</span>聽<span style="color: rgb(0, 0, 0);">HttpMethod聽method聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽GetMethod(聽url聽);<br /></span><span style="color: rgb(0, 128, 128);">聽9</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</span>聽<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);">聽{<br /></span><span style="color: rgb(0, 128, 128);">11</span>聽<span style="color: rgb(0, 0, 0);">聽聽聽聽client.executeMethod(聽method聽);<br /></span><span style="color: rgb(0, 128, 128);">12</span>聽<span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">13</span>聽<span style="color: rgb(0, 0, 0);">聽聽聽聽</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(聽method.getStatusCode(聽)聽</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">聽HttpStatus.SC_OK聽)聽{<br /></span><span style="color: rgb(0, 128, 128);">14</span>聽<span style="color: rgb(0, 0, 0);">聽聽聽聽聽聽聽聽String聽response聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽method.getResponseBodyAsString(聽);<br /></span><span style="color: rgb(0, 128, 128);">15</span>聽<span style="color: rgb(0, 0, 0);">聽聽聽聽聽聽聽聽System.out.println(聽response聽);<br /></span><span style="color: rgb(0, 128, 128);">16</span>聽<span style="color: rgb(0, 0, 0);">聽聽聽聽}<br /></span><span style="color: rgb(0, 128, 128);">17</span>聽<span style="color: rgb(0, 0, 0);">}聽</span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);">(聽HttpException聽he聽)聽{<br /></span><span style="color: rgb(0, 128, 128);">18</span>聽<span style="color: rgb(0, 0, 0);">聽聽聽聽System.out.println(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">HTTP聽Problem:聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">聽he.getMessage(聽)聽);<br /></span><span style="color: rgb(0, 128, 128);">19</span>聽<span style="color: rgb(0, 0, 0);">}聽</span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);">(聽IOException聽ioe聽)聽{<br /></span><span style="color: rgb(0, 128, 128);">20</span>聽<span style="color: rgb(0, 0, 0);">聽聽聽聽System.out.println(聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">IO聽Exeception:聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">聽ioe.getMessage(聽)聽);<br /></span><span style="color: rgb(0, 128, 128);">21</span>聽<span style="color: rgb(0, 0, 0);">}聽</span><span style="color: rgb(0, 0, 255);">finally</span><span style="color: rgb(0, 0, 0);">聽{<br /></span><span style="color: rgb(0, 128, 128);">22</span>聽<span style="color: rgb(0, 0, 0);">聽聽聽聽method.releaseConnection(聽);<br /></span><span style="color: rgb(0, 128, 128);">23</span>聽<span style="color: rgb(0, 0, 0);">聽聽聽聽method.recycle(聽);<br /></span><span style="color: rgb(0, 128, 128);">24</span>聽<span style="color: rgb(0, 0, 0);">}</span><span style="color: rgb(0, 128, 128);"></span><span style="color: rgb(0, 0, 0);"></span></div>聽聽聽聽 榪欐浠g爜鐢℉TTP GET鏂規硶鑾峰緱浜?/font> <font face="Georgia"> <a >http://www.discursive.com/jccook/</a>鐨勫唴瀹廣傚鏋滃搷搴旂殑鐘舵佺爜鏄疕ttpStatus.SC_OK(鍗?00錛夛紝涓嬪垪鍝嶅簲灝嗚杈撳嚭鍒版帶鍒跺彴錛?br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">html</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />聽</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">head</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />聽聽</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">title</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);">JCCook聽Example</span><span style="color: rgb(0, 0, 0);"></</span><span style="color: rgb(0, 0, 0);">title</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />聽</span><span style="color: rgb(0, 0, 0);"></</span><span style="color: rgb(0, 0, 0);">head</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />聽</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">body</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />聽聽</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">h1</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);">Hello聽World</span><span style="color: rgb(0, 0, 0);">!</</span><span style="color: rgb(0, 0, 0);">h1</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br />聽</span><span style="color: rgb(0, 0, 0);"></</span><span style="color: rgb(0, 0, 0);">body</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);"></</span><span style="color: rgb(0, 0, 0);">html</span><span style="color: rgb(0, 0, 0);">></span><span style="color: rgb(0, 0, 0);"><br /><br /></span></div><br />璁ㄨ錛?br />聽聽聽聽聽聽聽 娉ㄦ剰榪欐浠g爜涓寮傚父鐨勫鐞嗐傛墽琛屼竴涓畝鍗曠殑HTTP GET闇瑕佹崟鎹変袱涓紓甯革細HttpException鍜孖OException銆傚鏋滄槸鍙戠敓HTTP鍗忚閿欒鏃訛紝灝嗘姏鍑篐ttpException寮傚父;濡傛灉鏄彂鐢熸湁鍏崇綉緇滅殑閿欒鏃訛紝灝嗘姏鍑篒OException寮傚父銆傝繖涓绔犲悗闈㈢殑渚嬪瓙灝嗕細蹇界暐瀵瑰紓甯哥殑澶勭悊銆備綘搴旇瑕佺煡閬撴瘡涓嬈¤皟鐢╡xecuteMethod()閮借鐢ㄩ傚綋鐨則ry/catch鍧楀寘瑁廣?br />聽聽聽聽聽聽聽 GetMethod綾繪槸HttpMethod鎺ュ彛鐨勪竴縐嶅疄鐜般侶ttpMethod浼氳HttpClient鎵璋冪敤銆侶ttpMethod瀹炵幇綾葷殑鐢熷懡鍛ㄦ湡鏄緢綆鍗曠殑錛氫竴涓狧ttpMethod瀹炰緥琚垱寤猴紝鐒跺悗琚獺ttpClient璋冪敤錛涗竴鏃﹀搷搴旇媯嫻嬪埌浠ュ悗錛孒ttpMethod閲婃斁榪炴帴騫惰鍥炴敹浣跨敤銆傚綋HttpMethod璋冪敤浜唕ecycle()鏂規硶錛岀浉褰撲簬鍙戦佷簡涓涓俊鍙風粰緋葷粺琛ㄧず榪欎釜HttpMethod瀹炰緥鍙互鍐嶈浣跨敤銆俽eleaseConnection()鏂規硶鎸囩ずHttpClient閲婃斁鎺変笌榪欎釜HttpMethod鐩稿叧鑱旂殑榪炴帴銆傛棤璁哄湪浣跨敤HttpMethod瀹炰緥鐨勮繃紼嬩腑鍙戠敓浜嗕粈涔堬紝閮借璋冪敤releaseConnection()鏉ラ噴鏀劇綉緇滆祫婧愩?br />聽聽聽聽聽聽聽 涓鏃ttpClient鐨別xecuteMethod鏂規硶琚皟鐢紝浣犲彲浠ラ氳繃HttpMethod鐨刧etStatusCode()鏂規硶鏉ヨ幏寰楀搷搴旂殑鐘舵佺爜銆傝繖涓柟娉曡繑鍥炰竴涓猧nt錛屽搴斾簬HttpStatus綾葷殑public static final 鍙橀噺銆侶ttpStatus綾昏繕鍖呮嫭涓嬮潰涓浜涘父閲忥細SC_OK(200)錛孲C_NOT_FOUND(404)錛孲C_INTERNAL_SERVER_ERROR(500)錛孲C_MOVED_TEMPORARILY (302)錛孲C_UNAUTHORIZED(401)絳夌瓑銆傝鍙傜収HttpStatus鐨凧avadoc鏉ヨ幏寰楁墍鏈夌殑HTTP鐘舵佸垪琛ㄣ傚綋鏈嶅姟鍣ㄨ繑鍥炰竴涓敊璇殑HTTP鐘舵佹槸錛岄氬父榪樹細榪斿洖涓灝忔淇℃伅銆傝繖涓灝忔淇℃伅鍙互閫氳繃HttpMethod綾葷殑getStatusText()鏂規硶鑾峰緱銆?br />聽<br />鍙傝冿細<br />聽聽聽聽聽聽 鍙互浠嶳FC2616錛坔ttp://www.zvon.org/tmRFC/RFC2616/Output/index.html)鑾峰緱HTTP GET鏂規硶鐨勫畼鏂瑰畾涔夛紱<br />聽聽聽聽聽聽 瑕佽幏寰桯TTP 鐘舵佺爜鐨勫畬鏁村垪琛紝璇峰弬瑙?HttpStatus Javadoc聽 (http://jakarta.apache.org/commons/ httpclient/apidocs/index.html錛夈?br /></font> <img src ="http://www.tkk7.com/guangnian0412/aggbug/39044.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/guangnian0412/" target="_blank">guangnian</a> 2006-04-04 00:18 <a href="http://www.tkk7.com/guangnian0412/archive/2006/04/04/39044.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Jakarta Commons Cookbookhttp://www.tkk7.com/guangnian0412/archive/2006/04/03/39036.htmlguangnianguangnianMon, 03 Apr 2006 15:25:00 GMThttp://www.tkk7.com/guangnian0412/archive/2006/04/03/39036.htmlhttp://www.tkk7.com/guangnian0412/comments/39036.htmlhttp://www.tkk7.com/guangnian0412/archive/2006/04/03/39036.html#Feedback2http://www.tkk7.com/guangnian0412/comments/commentRss/39036.htmlhttp://www.tkk7.com/guangnian0412/services/trackbacks/39036.html鍏跺疄Jakarta Commons綾誨簱鍦↗ava涓殑鍦頒綅鏄緢閲嶈鐨勶紝瀹冧負Java紼嬪簭鍛樻彁渚涗簡寰堝鍙噸鐢ㄧ殑宸ュ叿銆傛渶榪戝湪鐪婮akarta Commons Cookbook 榪欐湰涔︼紝鏄嫳鏂囩増錛屽拷鐒舵湁鎯崇炕璇戝畠鐨勫啿鍔ㄣ傚氨浠庢垜鏈榪戠敤鍒扮殑HttpClient寮濮嬪惂.......

guangnian 2006-04-03 23:25 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 免费黄色福利视频| 免费A级毛片无码A∨中文字幕下载| 日本人的色道免费网站| 亚洲视频免费在线看| 2019中文字幕免费电影在线播放| 亚洲嫩草影院久久精品| 色欲色香天天天综合网站免费| 亚洲avav天堂av在线不卡| 在线观看片免费人成视频无码| 亚洲AV无码不卡在线播放| 久久久久高潮毛片免费全部播放| 久久久久亚洲AV无码专区首JN| 久久精品国产免费观看| 亚洲午夜无码久久| 国产精品极品美女免费观看| 久久亚洲AV成人无码国产电影 | 性一交一乱一视频免费看| 99亚偷拍自图区亚洲| 免费欧洲美女牲交视频| 国产日韩久久免费影院| 亚洲AV本道一区二区三区四区| 97在线视频免费公开观看| 精品亚洲456在线播放| 日韩亚洲国产二区| 久久精品无码精品免费专区| 亚洲国产成人在线视频| 精品无码国产污污污免费| 亚洲精品国产日韩无码AV永久免费网| 亚洲国产精品无码AAA片| 日本亚洲免费无线码| 免费人成视频在线播放| 亚洲韩国—中文字幕| 波多野结衣久久高清免费 | av免费不卡国产观看| 亚洲av无码一区二区三区在线播放 | 国产精品成人免费综合| 国产一区二区免费| 亚洲人成人伊人成综合网无码 | 免费无码一区二区三区蜜桃大 | 91亚洲视频在线观看| 免费一看一级毛片全播放|