执行RunKeeper的get请求

时间:2012-06-20 07:51:48

标签: android http-get

我正在尝试向RunKeeper API发送此请求:

  

GET / user HTTP / 1.1
  主持人:api.runkeeper.com
  授权:持票人xxxxxxxxxxxxxxxx
  接受: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 - 服务器遇到内部错误(),导致无法完成此请求。

我的错误是什么?

1 个答案:

答案 0 :(得分:3)

您使用的网址不正确。你应该只要求/user

添加一个接受标头:

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

您确定要正确添加凭据信息吗?该文档指出Authorization标头应该看起来像Bearer xxxxxxxxxxxxxxxx,而您的标头Basic ...get.addHeader("Authorization", "Bearer " + getAccessToken()); 。如果不进一步研究,也许这可能是解决方案:

{{1}}

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