当前位置: 首页 > 知识库问答 >
问题:

使用ApacheOltu的LinkedIn的HTTP响应代码:411

谢洛城
2023-03-14
    OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
    TokenRequestBuilder r = OAuthClientRequest
            .tokenLocation("https://www.linkedin.com/oauth/v2/accessToken")
            .setCode(code)
            .setGrantType(GrantType.AUTHORIZATION_CODE)
            .setClientId(LinkedInClientID)
            .setClientSecret(LinkedInClientSecret)
            .setRedirectURI("http://localhost:8080/authenticatedLinkedIn");

    Map<String,String> m = new HashMap<String,String>();
    m.put("Content-Type", "application/x-www-form-urlencoded");

    int bodyLength = r.buildBodyMessage().getBody().length();
    System.out.println("Body l = " + bodyLength);
    m.put("Content-Length", Integer.toString(bodyLength));
    r.buildHeaderMessage().setHeaders(m);
    OAuthClientRequest request = r.buildQueryMessage();
    OAuthJSONAccessTokenResponse tk = oAuthClient.accessToken(request, OAuth.HttpMethod.POST);

共有1个答案

裴楚青
2023-03-14

您需要发送一个POST请求,在body中包含params,Urlenconded...所以

第一个变化:

OAuthClientRequest request = r.buildQueryMessage();

与:

OAuthClientRequest request = r.buildBodyMessage();
 类似资料: