APK反编译源代码展示 - 南明离火平台提供

应用版本信息
应用名称:Farmer King
版本号:1.0
包名称:com.example.farmerking

MD5 校验值:0196aab07de1f50d20a13dec604b8a48

反编译源代码说明

NetworkUtils.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。


package com.example.farmerking;

import com.google.gson.Gson;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class NetworkUtils {
    private static final String API_URL = "https://api.farmer-king.com";
    private static final String TAG = "NetworkUtils";
    private static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
    private static final OkHttpClient client = new OkHttpClient();

    public static void postRequest(String str, Object obj, final NetworkCallback networkCallback) {
        client.newCall(new Request.Builder().url(API_URL + str).post(RequestBody.create(new Gson().toJson(obj), JSON)).build()).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException iOException) {
                NetworkCallback.this.onFailure(iOException);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    NetworkCallback.this.onSuccess(response.body().string());
                } else {
                    NetworkCallback.this.onFailure(new IOException("Request Failed: " + response.message()));
                }
            }
        });
    }
}