首页 > 解决方案 > 获取 Post Request Retrofit OkHttp 的 URL Header 响应

问题描述

我一直在阅读很多资源,但我似乎无法得到答案。我要做的是从 POST 请求中获取标头响应,并且该响应是使用 Retrofit 和 OK 的 URL。我能够成功获得除 URL 之外的其他响应。请帮忙。谢谢你。

public void getAllProfileRequest() {
        final RetrofitClient retrofit = new RetrofitClient();
        APIGetAllProfile apiGetAllProfile = retrofit.getClient().create(APIGetAllProfile.class);
        Call<List<JSONGetAllProfile>> callProfile = apiGetAllProfile.getResponse();

        callProfile.enqueue(new Callback<List<JSONGetAllProfile>>() {
            @Override
            public void onResponse(Call<List<JSONGetAllProfile>> call, Response<List<JSONGetAllProfile>> response) {
                if(response.body() != null) {
                    List<JSONGetAllProfile> getAllProfile = response.body();

                    String[] getAllProfileArr = new String[getAllProfile.size()];

                    for (int i = 0; i < getAllProfile.size(); i++) {
                        getAllProfileArr[i] = getAllProfile.get(i).getIdentificationProfileId();
                        String url = getAllProfileArr[i];
                        String FILE_NAME = recordWavMaster.audioFilePath + ".wav";

                        //Identify
                        File file = new File(Environment.getExternalStorageDirectory() + File.separator
                                + "AudioRecord" + FILE_NAME);

                        IdentifyBody identifyBody = new IdentifyBody(file);

                        APIPostIdentify apiPostIdentify = retrofit.getClient().create(APIPostIdentify.class);
                        Call<IdentifyBody> callIdentify = apiPostIdentify.identifyUser(url, "true", identifyBody);
                        callIdentify.enqueue(new Callback<IdentifyBody>() {
                            @Override
                            public void onResponse(Call<IdentifyBody> call, Response<IdentifyBody> response) {
                                Log.e("URL RESPONSE: ", response.raw().request().url() + " ?");

                                Headers headers = response.headers();
                                String url = response.headers().get("Expires");
                            }

                            @Override
                            public void onFailure(Call<IdentifyBody> call, Throwable t) {

                            }
                        });
                    }
                }
            }

            @Override
            public void onFailure(Call<List<JSONGetAllProfile>> call, Throwable t) {

            }
        });

    }

标签: androidretrofit2okhttp

解决方案


推荐阅读