我正试图向RunKeeper API提出这个请求:
获取/用户http/1.1
主机:api.runkeeper.com
授权:持票人
接受:application/vnd.com.runkeeper.user+json
我的代码:

private static final String BASEURL = "http://api.runkeeper.com";

public HttpResponse getUserInformation() throws IOException {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF_8");
    HttpProtocolParams.setUseExpectContinue(params, false);

    client.setParams(params);
    HttpGet get = new HttpGet(BASEURL.concat("/user"));
    String credentials = getCredentials();
    get.addHeader("Authorization", "Basic " + credentials);
    get.addHeader("Accept", "application/vnd.com.runkeeper.User+json");
    return client.execute(get);
}

private String getCredentials() {
    String source = "Authorization" + ":" + "Bearer " + getAccessToken();
    String ret = Base64.encodeToString(source.getBytes(), Base64.URL_SAFE | Base64.NO_WRAP);
    return ret;
}

但我一直在想:
HTTP状态500-服务器遇到内部错误(),无法满足此请求。
我在这里犯了什么错?

最佳答案

您使用的URL不正确。你应该只请求/user
添加包含以下内容的接受头:

get.addHeader("Accept", "application/vnd.com.runkeeper.User+json");

您确定您正确地添加了凭据信息吗?文档说明授权头应该看起来像Bearer xxxxxxxxxxxxxxxx,而您的头应该是Basic ...。如果不进一步研究,也许这就是解决之道:
get.addHeader("Authorization", "Bearer " + getAccessToken());

如果仍然无法正常工作,this页指出,如果收到内部服务器错误,应与他们联系以解决问题。我想这可以在this Google Group中完成。

10-04 19:56