A
A
Andrey Goroshko2018-08-14 10:12:40
Android
Andrey Goroshko, 2018-08-14 10:12:40

Where can there be an error in the put request?

In my application I am trying to refresh an access token using a refresh_token. Here in the documentation I have a successful server response with the correct request:
HTTP 200

{
    "expires_in": UNIX_TIMESTAMP,
    "access_token": str,
    "refresh_token": str
}

I created a request in the interface:
@Headers("Content-type: application/json")
Call<GetToken> getNewToken (@Path("refresh_token") String refresh_token);

then I build a query in the class itself:
public void updateToken() {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

        tok_pref2 = Objects.requireNonNull(getActivity()).getSharedPreferences(REFRESH_TOKEN,Context.MODE_PRIVATE);
        String token = tok_pref2.getString(REFRESH_TOKEN,"");

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://сервер/")
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        APIService mAPIService2 = retrofit.create(APIService.class);

        mAPIService2.getNewToken(token).enqueue(new Callback<GetToken>() {
            @Override
            public void onResponse(@NonNull Call<GetToken> call,@NonNull Response<GetToken> response) {

            }

            @Override
            public void onFailure(@NonNull Call<GetToken> call,@NonNull Throwable t) {
                Toast.makeText(getContext(),"Failure!!!",LENGTH_LONG).show();
            }
        });

    }

in the body of the request, I insert a refresh token that I previously saved in sharedpreferences, I checked that it is inserted normally when requested, but for some reason I get this response:
<-- 404 https://сервер/v1/токен (210ms)
   
    Content-Length: 41
    P3P: policyref="/w3c/p3p.xml", CP="NOI ADM DEV COM NAV OUR STP"
    Keep-Alive: timeout=5, max=100
    Connection: Keep-Alive
    Content-Type: application/json
08-14 03:04:54.257 3345-3394/com.example.developer_4.test_login D/OkHttp: {"message": "not_found", "error_code": 5}
    <-- END HTTP (41-byte body)

maybe I made a mistake somewhere when sending the request, I will be very grateful for the help.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mikhail Chvarkov, 2018-08-14
@Drew20

Are you sure that the token should be sent in the url? 404, it doesn't see that url. I suspect this is the case.

M
mayorovp, 2015-01-28
@mayorovp

double.Parse(textBox1.Text); - what decimal separator is used?
If you use a dot, then you should write double.Parse(textBox1.Text, CultureInfo.InvariantCulture);

A
Alexey Nemiro, 2015-01-28
@AlekseyNemiro

The point is the decimal separator:

string value = textBox1.Text;
// меняем разделитель на текущий
value = System.Text.RegularExpressions.Regex.Replace(value, @",|\.", System.Globalization.NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator);
// преобразуем строку в число
var result = double.Parse(value);

Type conversion .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question