Search in sources :

Example 76 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project C3 by Hi5App.

the class HttpUtilsQualityInspection method getSwcWithOkHttp.

public static void getSwcWithOkHttp(JSONObject userInfo, JSONObject bBox, Callback callback) {
    try {
        RequestBody body = RequestBody.create(JSON, String.valueOf(new JSONObject().put("bb", bBox).put("user", userInfo)));
        asyncPostRequest(URL_GET_SWC, body, callback);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JSONObject(org.json.JSONObject) RequestBody(okhttp3.RequestBody)

Example 77 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project C3 by Hi5App.

the class HttpUtilsQualityInspection method getArborMarkerListWithOkHttp.

public static void getArborMarkerListWithOkHttp(JSONObject userInfo, String arborName, Callback callback) {
    try {
        RequestBody body = RequestBody.create(JSON, String.valueOf(new JSONObject().put("user", userInfo).put("arborname", arborName)));
        asyncPostRequest(URL_GET_ARBOR_MARKER_LIST, body, callback);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JSONObject(org.json.JSONObject) RequestBody(okhttp3.RequestBody)

Example 78 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project C3 by Hi5App.

the class HttpUtilsQualityInspection method getArborWithOkHttp.

public static void getArborWithOkHttp(JSONObject userInfo, Callback callback) {
    try {
        RequestBody body = RequestBody.create(JSON, String.valueOf(new JSONObject().put("user", userInfo)));
        asyncPostRequest(URL_GET_ARBOR, body, callback);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JSONObject(org.json.JSONObject) RequestBody(okhttp3.RequestBody)

Example 79 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project AndroidFastDevFrame by linglongxin24.

the class Myapplication method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    // x.Ext.init(this);
    CustomActivityOnCrash.install(this);
    CustomActivityOnCrash.setDebugMode(BuildConfig.DEBUG);
    // http请求初始化设置
    Http.getHttp().addInterceptor(new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            Request original = chain.request();
            Request.Builder requestBuilder = original.newBuilder();
            requestBuilder.addHeader("Userid", "589");
            requestBuilder.addHeader("FAToken", "VTMWBVZO");
            requestBuilder.addHeader("Content-Type", "application/json");
            RequestBody requestBody = original.body();
            requestBuilder.method(original.method(), requestBody);
            Request request = requestBuilder.build();
            Logger.d("request.headers().toString()=" + request.headers().toString());
            return chain.proceed(request);
        }
    });
    Http.getHttp().setDebugMode(BuildConfig.DEBUG);
    Http.getHttp().init(ApiService.class, ApiService.baseUrl, "returnCode", "data", "returnMsg", 200);
    Http.getHttp().setShowMessageModel(MessageManager.MessageModel.All);
    Http.getHttp().setErrorMessage("网络开小差了");
    // AppConfig.setAppLeftResId(R.drawable.pub_arrow_back_write);
    if (LeakCanary.isInAnalyzerProcess(this)) {
        // You should not init your app in this process.
        return;
    }
    LeakCanary.install(this);
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) IOException(java.io.IOException) Interceptor(okhttp3.Interceptor) RequestBody(okhttp3.RequestBody)

Example 80 with RequestBody

use of com.reprezen.kaizen.oasparser.model3.RequestBody in project AndroidFastDevFrame by linglongxin24.

the class RetrofitManager method getRequestBody.

private String getRequestBody(MultipartBody.Part part) {
    Class<?> personType = part.getClass();
    // 访问私有属性
    Field field = null;
    try {
        field = personType.getDeclaredField("body");
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    }
    field.setAccessible(true);
    try {
        RequestBody requestBody = (RequestBody) field.get(part);
        MediaType contentType = requestBody.contentType();
        if (contentType.type().equals("multipart")) {
            Buffer buffer = new Buffer();
            requestBody.writeTo(buffer);
            Charset UTF8 = Charset.forName("UTF-8");
            Charset charset = contentType.charset(UTF8);
            return buffer.readString(charset);
        } else if (contentType.type().equals("image")) {
            if (requestBody != null) {
                return convertFileSize(requestBody.contentLength());
            } else {
                return "0b";
            }
        // Class<?> requestBodyClass = requestBody.getClass();
        // 
        // //访问私有属性
        // Field fileRequestBodyClass = null;
        // try {
        // fileRequestBodyClass = requestBodyClass.getDeclaredField("file");
        // 
        // 
        // fileRequestBodyClass.setAccessible(true);
        // File file = (File) fileRequestBodyClass.get(requestBody);
        // Logger.d("file=" + file.getPath());
        // } catch (NoSuchFieldException e) {
        // e.printStackTrace();
        // } catch (Exception e) {
        // e.printStackTrace();
        // }
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "";
}
Also used : Buffer(okio.Buffer) Field(java.lang.reflect.Field) MediaType(okhttp3.MediaType) Charset(java.nio.charset.Charset) IOException(java.io.IOException) RequestBody(okhttp3.RequestBody)

Aggregations

RequestBody (okhttp3.RequestBody)1358 Request (okhttp3.Request)785 Response (okhttp3.Response)598 IOException (java.io.IOException)420 Test (org.junit.Test)235 OkHttpClient (okhttp3.OkHttpClient)216 MultipartBody (okhttp3.MultipartBody)213 MediaType (okhttp3.MediaType)204 Call (okhttp3.Call)198 JSONObject (org.json.JSONObject)183 ResponseBody (okhttp3.ResponseBody)177 Callback (okhttp3.Callback)115 FormBody (okhttp3.FormBody)106 Buffer (okio.Buffer)98 File (java.io.File)92 Map (java.util.Map)90 JsonObject (io.vertx.core.json.JsonObject)89 Headers (okhttp3.Headers)88 HashMap (java.util.HashMap)83 HttpUrl (okhttp3.HttpUrl)80