1. 程式人生 > >okhttp請求返回值只有一個數值

okhttp請求返回值只有一個數值

返回值如上圖所示,

body裡都是為空,code=200,就是拿不到值正確姿勢如下:response.body().string()

  final Request request = new Request.Builder()
                .url(url)
                .build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                e.printStackTrace();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                int anInt = Integer.parseInt(response.body().string());
                System.out.println("我是非同步執行緒,執行緒Id為:" + anInt);
            }
        });