java.net.HttpRetryException: 由于服务器身份验证,无法在流模式下重试

java.net.HttpRetryException: cannot retry due to server authentication, in streaming mode

我正在尝试获取授权后用户的访问令牌和访问令牌机密。当我点击授权应用程序时出现此异常。下面是回调控制器中的代码。我在消费者应用程序设置中配置了回调 url。

@RequestMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public void connect(@RequestParam("oauth_token") String oauthToken,@RequestParam("oauth_verifier") String oauthVerifier){

    TwitterConnectionFactory connectionFactory = new TwitterConnectionFactory( "XXX", "XXX" );
    OAuth1Operations oauthOperations = connectionFactory.getOAuthOperations();

    OAuthToken requestToken = oauthOperations.fetchRequestToken("htt*://localhost:8080/svc/v1/authorize",null);
    ///String authorizeUrl = oauthOperations.buildAuthorizeUrl(requestToken.getValue(),null);

    OAuthToken accessToken = oauthOperations.exchangeForAccessToken(new AuthorizedRequestToken(requestToken, oauthVerifier), null);

    String consumerKey = "..."; // The application's consumer key
    String consumerSecret = "..."; // The application's consumer secret
    String token = accessToken.getValue();
    String tokenSecret = accessToken.getSecret();
    System.out.println("token: "+token);
    Twitter twitter = new TwitterTemplate( consumerKey, consumerSecret, token, tokenSecret );


}

我可以在授权后获取accesstoken 和accesstokensecret。 问题在于创建 requestToken。替换OAuthToken的对象创建如下。

OAuthToken requestToken = new OAuthToken(oauthToken, oauthVerifier);

成功了。