简体   繁体   English

Ruby on Rails API与Android

[英]Ruby on Rails api with android

I am having trouble getting a 401 unauthorized response from the server,I am doing a "GET" call from a ruby on rails api the oauth token is in the header like this. 我无法从服务器获取401未经授权的响应,我正在从Rails api上的ruby进行“ GET”调用,而oauth令牌位于标头中。

  urlConnection = (HttpURLConnection) url.openConnection();
            OAuth =   "bearer " + Base64.encodeToString(userpass.getBytes(), Base64.NO_WRAP);
            Log.e("auth", oAuth_token);
            urlConnection.setRequestMethod("GET");
            urlConnection.setRequestProperty("Authorization", OAuth);
            urlConnection.setRequestProperty("Content-Type", "application/json");
            urlConnection.setRequestProperty("Accept", "application/json");
            urlConnection.connect();

Userpass is the actual token. Userpass是实际的令牌。

This works in postman as well as on iOS but android is getting a 401 这适用于邮递员以及iOS,但android得到401

The Bearer Token Usage specification ( RFC 6750 ) is a bit confusing. 承载令牌使用规范( RFC 6750 )有点令人困惑。 You don't have to base64-encode the access token before use. 使用之前,您无需对访问令牌进行base64编码。 To be concrete, your code should be simply like this: 具体来说,您的代码应如下所示:

OAuth = "Bearer " + userpass;

See this discussion where the questioner confessed he had had the same confusion as yours. 在发问者承认他和您一样困惑的地方,请参见此讨论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM