如何将 OkHttp REST 调用的响应设置为变量并在另一个 class 文件中使用?

How to I set the response of OkHttp REST call to a variable and use in another class file?

我有一段 Java 使用 OkHttp 进行休息调用的代码。

如何设置对变量的响应,然后在另一个 class 文件中调用该变量?

这是我目前的代码。我认为这行不通。请帮助我修复并了解如何正确实施:

public abstract class PullID extends AsyncTask {

    String url ="https://exampleEndPoint.com";
    String id_needed = " ";

    OkHttpClient client = new OkHttpClient();

    String doGetRequest(String url) throws IOException {
        Request request = new Request.Builder()
                .url(url)
                .build();

        Response response = client.newCall(request).execute();
        return response.body().string();
    }

    public String getPullID() {

        return this.PullID;
    }

    public String setPullID(String current_ID) {
       this.PullID = current_ID;
        return PullID;
    }

}

谢谢。

我最终使用 URI Builder 来简化这件事。 它现在对我有用。