我需要從commons-httpclient-3.0.jar傳遞給commons-httpclient-3.1.jar 但更改jar我的代碼不再工作。 問題是新庫自動對傳入的uri進行編碼。 有沒有辦法避免這種情況? 我必須與雅虎API進行交互,我不得編碼URI,否則我無法訪問服務。 這裏有一段我的代碼,比較兩條印刷線,我觀察到了傳遞的URI和使用的URI之間的區別。使用commons-httpclient-3.X.jar的Java問題
GetMethod getMethod = new GetMethod();
try {
URI uri = new URI(DeliciousApi.generateRequestToken(), false);
getMethod.setURI(uri);
System.out.println("Passed URI: " + uri.getURI());
int statusCode = client.executeMethod(getMethod);
if (statusCode != HttpStatus.SC_OK) {
System.out.println("Used URI: " + getMethod.getURI());
System.err.println("getMethod failed: " + getMethod.getStatusLine());
}
而這是輸出:
Passed URI: https://api.login.yahoo.com/oauth/v2/get_request_token?oauth_nonce=ce4630523j788f883f76314ed3965qw9&oauth_timestamp=1277236486&oauth_consumer_key=hd7sHfs5YVFuh3DRTUFgFgF7GcF4RDtsTXStGdRyJJf7WSuShQAShd2JdiwjIibHsU8YFDgshk7hd32xjA6isnNsT7SkbLS8YDHy&oauth_signature_method=plaintext&oauth_signature=53h8x475a66v238j7f43456lhhgg8s7457fwkkdd%26&oauth_version=1.0&xoauth_lang_pref="en-us"&oauth_callback=oob
Used URI: https://api.login.yahoo.com/oauth/v2/get_request_token?oauth_nonce=ce4630523j788f883f76314ed3965qw9&oauth_timestamp=1277236486&oauth_consumer_key=hd7sHfs5YVFuh3DRTUFgFgF7GcF4RDtsTXStGdRyJJf7WSuShQAShd2JdiwjIibHsU8YFDgshk7hd32xjA6isnNsT7SkbLS8YDHy&oauth_signature_method=plaintext&oauth_signature=53h8x475a66v238j7f43456lhhgg8s7457fwkkdd%2526&oauth_version=1.0&xoauth_lang_pref=%22en-us%22&oauth_callback=oob
getMethod失敗:HTTP/1.1 401禁止
coppia:oauth_problem signature_invalid
particolarly:
%26 & oauth_version - >%2526 & oauth_version
和
xoauth_lang_pref = 「EN-US」 - > xoauth_lang_pref =%22en美%22
非常感謝您的提示!這解決了我的麻煩!我很愚蠢,因爲我從來沒有購買過! :-) – AndyPower 2010-06-23 21:42:46