I need to pass from commons-httpclient-3.0.jar to commons-httpclient-3.1.jar
but changing the jar my code doesn’t work any more.
The problem is that the new library encode automatically the passed uri.
Is there a way to avoid this?
I must interact with Yahoo API and I mustn’t encode the URI otherwise I can’t access to the services.
Here there is a scratch of my code, comparing the two printing line I observe the difference between the passed URI and the used one.
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());
}
And this is the output:
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 failed: HTTP/1.1 401 Forbidden
coppia: oauth_problem signature_invalid
particolarly:
%26&oauth_version –> %2526&oauth_version
and
xoauth_lang_pref=”en-us” –> xoauth_lang_pref=%22en-us%22
You can avoid encoding by doing this,
However, you might get exception on your original URL, which is not properly encoded. You need to encode double quotes. Even better, get rid of it.