0

我想通过改造向服务器发出 POST 请求,但我总是收到错误 422。我只想知道我做错了什么还是服务器故障。

改造电话:

OkHttpClient.Builder duplicateTimeSessionClient = new kHttpClient.Builder();

duplicateTimeSessionClient.addInterceptor(newInterceptor() {
    @Override
    public okhttp3.Response intercept(Chain chain) throws IOException {
        Request original = chain.request();

        Request request = original.newBuilder()
                                    .header("Authorization", "Bearer "+sharedPreferences.getString("access_token",""))
                                    .header("Accept", "application/vnd.web_app+json; version=1")
                                    .method(original.method(), original.body())
                                    .build();

        return chain.proceed(request);
    }
});

OkHttpClient client = duplicateTimeSessionClient.build();

final Retrofit duplicateTimeSession = new Retrofit.Builder()
                            .baseUrl(context.getString(R.string.URL))
                            .addConverterFactory(ScalarsConverterFactory.create())
                            .addConverterFactory(GsonConverterFactory.create())
                            .client(client)
                            .build();

duplicateService = duplicateTimeSession.create(DuplicateTimeSessionInterface.class);                   

Call<String> duplicateTimeSessionCall = duplicateService.duplicate(createJSON(pos),"api/time-sessions");

duplicateTimeSessionCall.enqueue(new Callback<String>() {
    @Override
    public void onResponse(Call<String> call, Response<String> response) {
        Log.i("time-session post",Integer.toString(response.code()));
    }

    @Override
    public void onFailure(Call<String> call, Throwable t) {}
});

界面:

public interface DuplicateTimeSessionInterface {
    @POST
    Call<String>duplicate(@Body JSONObject jsonObject, @Url String url);
}

编辑:

相同的 JSON 在浏览器或 iPhone 上工作,一些类似的调用在 Android 上工作,这个只是不想通过。

4

0 回答 0