Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用commons-httpclient-3.X.jar时出现Java问题_Java_Api_Yahoo_Urlencode_Apache Commons Httpclient - Fatal编程技术网

使用commons-httpclient-3.X.jar时出现Java问题

使用commons-httpclient-3.X.jar时出现Java问题,java,api,yahoo,urlencode,apache-commons-httpclient,Java,Api,Yahoo,Urlencode,Apache Commons Httpclient,我需要从commons-httpclient-3.0.jar传递到commons-httpclient-3.1.jar 但是更改jar我的代码不再有效了。 问题是新库会自动对传递的uri进行编码。 有没有办法避免这种情况? 我必须与YahooAPI交互,我不能对URI进行编码,否则我无法访问服务。 这里是我的代码的一个划痕,通过比较两个打印行,我观察到传递的URI和使用的URI之间的差异 GetMethod getMethod = new GetMethod(); try {

我需要从commons-httpclient-3.0.jar传递到commons-httpclient-3.1.jar 但是更改jar我的代码不再有效了。 问题是新库会自动对传递的uri进行编码。 有没有办法避免这种情况? 我必须与YahooAPI交互,我不能对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被禁止

coppia:oauth\u问题签名\u无效

特别是:

%26和oauth_版本->%2526和oauth_版本


xoauth\u lang\u pref=en-us->xoauth\u lang\u pref=%22en-us%22

在此处使用setUri后跟setQueryStringinsert字符串有效吗?我似乎记得这样做可以更好地控制查询字符串…

这样做可以避免编码

      URI uri = new URI(DeliciousApi.generateRequestToken(), true);

然而,您的原始URL可能会出现异常,因为它没有正确编码。您需要对双引号进行编码。更好的是,把它扔掉。

谢谢你的回答,但我以前已经尝试过这个解决方案,结果是一样的。在我的项目中,我必须使用api commons-httpclient-3.1.jar,但我可以更改调用yahoo服务的代码。有没有其他api,我可以使用互动与雅虎?非常感谢你的提示!这解决了我的麻烦!我很愚蠢,因为我以前从来没有这样做过-