package Net;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import okhttp3.Cache;
import okhttp3.Callback;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;


public class OkHttpUtils {
	public static final long DEFAULT_READ_TIMEOUT_MILLIS = 15 * 1000;
    public static final long DEFAULT_WRITE_TIMEOUT_MILLIS = 20 * 1000;
    public static final long DEFAULT_CONNECT_TIMEOUT_MILLIS = 20 * 1000;
    private static final long HTTP_RESPONSE_DISK_CACHE_MAX_SIZE = 10 * 1024 * 1024;
    private static volatile OkHttpUtils sInstance;
    private OkHttpClient okHttpClient;

    public OkHttpUtils() {

    	okHttpClient = new OkHttpClient();  
    }
    
    public byte[] OkHttpPost(String url, byte[] data){
    	byte[] ret = null;
    	RequestBody body = RequestBody.create(MediaType.parse("application/octet-stream"),data);  
    	
    	Request request=new Request.Builder()
    	        .url(url)
    	        .post(body)  
    	        .build();  
    	try {  
    	    Response response = okHttpClient.newCall(request).execute();  
    	    ret = response.body().bytes();
    	} catch (IOException e) {  
    	    e.printStackTrace();//响应失败了，进行响应操作  
    	}  

    	return ret;
    }

}
