我需要从 commons-httpclient-3.0.jar 传递到 commons-httpclient-3.1.jar 但更改 jar 我的代码不再起作用。问题是新库会自动对传递的 uri 进行编码。有没有办法避免这种情况?我必须与 Yahoo API 交互,并且我不能对 URI 进行编码,否则我将无法访问服务。这里有一个我的代码的划痕,比较两个打印行我观察到传递的 URI 和使用的 URI 之间的差异。
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 禁止
副本:oauth_problem signature_invalid
特别是:
%26&oauth_version --> %2526&oauth_version
和
xoauth_lang_pref="en-us" --> xoauth_lang_pref=%22en-us%22