2016-03-31 11 views

答えて

1

実際にあなたの体を暗号化するためにインターセプタを使用することができます。

public class EncryptionInterceptor implements Interceptor { 

private static final String TAG = EncryptionInterceptor.class.getSimpleName(); 

private static final boolean DEBUG = true; 

@Override 
public Response intercept(Chain chain) throws IOException { 

    Request request = chain.request(); 
    RequestBody oldBody = request.body(); 
    Buffer buffer = new Buffer(); 
    oldBody.writeTo(buffer); 
    String strOldBody = buffer.readUtf8(); 
    MediaType mediaType = MediaType.parse("text/plain; charset=utf-8"); 
    String strNewBody = CodeMachine.encrypt(strOldBody); 
    RequestBody body = RequestBody.create(mediaType, strNewBody); 
    request = request.newBuilder().header("Content-Type", body.contentType().toString()).header("Content-Length", String.valueOf(body.contentLength())).method(request.method(), body).build(); 
    return chain.proceed(request); 
} 

private static String encrypt(String){ 
    //your code 
} 
} 

あなたの改造にインターセプタを追加します。

client = new OkHttpClient.Builder().addNetworkInterceptor(new   EncryptionInterceptor()).build(); 
retrofit = new Retrofit.Builder().client(client).build(); 

よりインターセプタについて:https://github.com/square/okhttp/wiki/Interceptors

関連する問題