本文整理汇总了Java中com.zhy.http.okhttp.OkHttpUtils类的典型用法代码示例。如果您正苦于以下问题:Java OkHttpUtils类的具体用法?Java OkHttpUtils怎么用?Java OkHttpUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OkHttpUtils类属于com.zhy.http.okhttp包,在下文中一共展示了OkHttpUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postFile
import com.zhy.http.okhttp.OkHttpUtils; //导入依赖的package包/类
public void postFile(View view)
{
File file = new File(Environment.getExternalStorageDirectory(), "messenger_01.png");
if (!file.exists())
{
Toast.makeText(MainActivity.this, "文件不存在,请修改文件路径", Toast.LENGTH_SHORT).show();
return;
}
String url = mBaseUrl + "user!postFile";
OkHttpUtils
.postFile()
.url(url)
.file(file)
.build()
.execute(new MyStringCallback());
}
示例2: wrapRequestBody
import com.zhy.http.okhttp.OkHttpUtils; //导入依赖的package包/类
@Override
protected RequestBody wrapRequestBody(RequestBody requestBody, final Callback callback)
{
if (callback == null) return requestBody;
CountingRequestBody countingRequestBody = new CountingRequestBody(requestBody, new CountingRequestBody.Listener()
{
@Override
public void onRequestProgress(final long bytesWritten, final long contentLength)
{
OkHttpUtils.getInstance().getDelivery().execute(new Runnable()
{
@Override
public void run()
{
callback.inProgress(bytesWritten * 1.0f / contentLength,contentLength,id);
}
});
}
});
return countingRequestBody;
}
示例3: buildRequest
import com.zhy.http.okhttp.OkHttpUtils; //导入依赖的package包/类
@Override
protected Request buildRequest(RequestBody requestBody)
{
if (method.equals(OkHttpUtils.METHOD.PUT))
{
builder.put(requestBody);
} else if (method.equals(OkHttpUtils.METHOD.DELETE))
{
if (requestBody == null)
builder.delete();
else
builder.delete(requestBody);
} else if (method.equals(OkHttpUtils.METHOD.HEAD))
{
builder.head();
} else if (method.equals(OkHttpUtils.METHOD.PATCH))
{
builder.patch(requestBody);
}
return builder.build();
}
示例4: buildCall
import com.zhy.http.okhttp.OkHttpUtils; //导入依赖的package包/类
public Call buildCall(Callback callback)
{
request = generateRequest(callback);
if (readTimeOut > 0 || writeTimeOut > 0 || connTimeOut > 0)
{
readTimeOut = readTimeOut > 0 ? readTimeOut : OkHttpUtils.DEFAULT_MILLISECONDS;
writeTimeOut = writeTimeOut > 0 ? writeTimeOut : OkHttpUtils.DEFAULT_MILLISECONDS;
connTimeOut = connTimeOut > 0 ? connTimeOut : OkHttpUtils.DEFAULT_MILLISECONDS;
clone = OkHttpUtils.getInstance().getOkHttpClient().newBuilder()
.readTimeout(readTimeOut, TimeUnit.MILLISECONDS)
.writeTimeout(writeTimeOut, TimeUnit.MILLISECONDS)
.connectTimeout(connTimeOut, TimeUnit.MILLISECONDS)
.build();
call = clone.newCall(request);
} else
{
call = OkHttpUtils.getInstance().getOkHttpClient().newCall(request);
}
return call;
}
示例5: initialize
import com.zhy.http.okhttp.OkHttpUtils; //导入依赖的package包/类
private static void initialize(boolean isHttps, InputStream[] online, InputStream loc, String password) {
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
CookieJarImpl cookieJar = new CookieJarImpl(new PersistentCookieStore(context));
HttpsUtils.SSLParams sslParams = null;
if (isHttps) {
sslParams = HttpsUtils.getSslSocketFactory(online, loc, password);
}
if (sslParams != null) {
httpClientBuilder.sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager);
}
httpClientBuilder.connectTimeout(MAX_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS)
.readTimeout(MAX_READ_TIMEOUT, TimeUnit.MILLISECONDS);
OkHttpUtils.initClient(httpClientBuilder.build());
isInitialized = true;
LogUtil.e("OkHttpClient初始化:支持Https = " + isHttps);
}
示例6: onCreate
import com.zhy.http.okhttp.OkHttpUtils; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CUIAgent.fixFontScale(this);
DEBUG = BApplication.DEBUG;
OkHttpUtils.getInstance();
app = (BApplication) getApplication();
BApplication.addActivity(this);
activity = this;
if (BuildConfig.DEBUG) testInject();
// 隐藏状态栏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
示例7: multiFileUpload
import com.zhy.http.okhttp.OkHttpUtils; //导入依赖的package包/类
public void multiFileUpload(View view)
{
File file = new File(Environment.getExternalStorageDirectory(), "messenger_01.png");
File file2 = new File(Environment.getExternalStorageDirectory(), "test1#.txt");
if (!file.exists())
{
Toast.makeText(MainActivity.this, "文件不存在,请修改文件路径", Toast.LENGTH_SHORT).show();
return;
}
Map<String, String> params = new HashMap<>();
params.put("username", "张鸿洋");
params.put("password", "123");
String url = mBaseUrl + "user!uploadFile";
OkHttpUtils.post()//
.addFile("mFile", "messenger_01.png", file)//
.addFile("mFile", "test1.txt", file2)//
.url(url)
.params(params)//
.build()//
.execute(new MyStringCallback());
}
示例8: startCheck
import com.zhy.http.okhttp.OkHttpUtils; //导入依赖的package包/类
public void startCheck(Context context) {
mcontext = context;
if (App.ignore) {
return;
}
OkHttpUtils//
.get()//
.url(Constant.APK_URL)//
.build().execute(new StringCallback() {
@Override
public void onError(Call call, Exception e) {
}
@Override
public void onResponse(String s) {
Message message = new Message();
message.what = 0;
message.obj = s;
mhanler.sendMessage(message);
}
});
}
示例9: onCreate
import com.zhy.http.okhttp.OkHttpUtils; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
if (DEBUG == true) {
CrashHandler crashHandler = CrashHandler.getInstance();
crashHandler.init(getApplicationContext());
}
// mQueue = Volley.newRequestQueue(getApplicationContext());
cookieJar =
new SimpleCookieJar(new SetCookieCache(),
new SharedPrefsCookiePersistor(getApplicationContext()));
// HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null, null, null);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.cookieJar(cookieJar)
.build();
OkHttpUtils.initClient(okHttpClient);
preferenceE = getSharedPreferences("overwall", MODE_PRIVATE).edit();
preferenceR = getSharedPreferences("overwall", MODE_PRIVATE);
}
示例10: checkForUpdate
import com.zhy.http.okhttp.OkHttpUtils; //导入依赖的package包/类
private void checkForUpdate() {
OkHttpUtils.get().url(updateUrl)
.build()
.connTimeOut(2000)
.execute(new StringCallback() {
@Override
public void onError(Call call, Exception e) {
handler.sendEmptyMessageDelayed(1, 1000);
}
@Override
public void onResponse(String response) {
Gson gson = new Gson();
versionInfo = gson.fromJson(response, VersionBean.class);
hasNewVersion();
}
});
}
示例11: initCodeImg
import com.zhy.http.okhttp.OkHttpUtils; //导入依赖的package包/类
/**
* 加载验证码
*/
private void initCodeImg() {
//加载验证码
OkHttpUtils.get().url(codeUrl).build()
.connTimeOut(3000)
.execute(new BitmapCallback() {
@Override
public void onError(Call call, Exception e) {
//应该给验证码设置一个图片
//不在校园网环境
if (tv_error.getVisibility() == View.INVISIBLE) {
tv_error.setVisibility(View.VISIBLE);
}
tv_error.setText("当前不是校园网环境");
}
@Override
public void onResponse(Bitmap response) {
ivCodes.setImageBitmap(response);
}
});
}
示例12: getUserInfo
import com.zhy.http.okhttp.OkHttpUtils; //导入依赖的package包/类
/**
* 获得用户基本信息
*/
private void getUserInfo() {
OkHttpUtils.get().url(mainUrl)
.addHeader("Referer", mainUrl)
.addHeader("Host", "210.44.159.5")
.build().execute(new StringCallback() {
@Override
public void onError(Call call, Exception e) {
//获取基本信息失败
}
@Override
public void onResponse(String response) {
//解析html,获得个人信息,主要获得账号
baseInfoMap = ParseCardInfo.parse(response);
if (baseInfoMap.size() != 0) {
initTitleUI();
getTodayData();
historyInfo();
}
}
});
}
示例13: historyInfo
import com.zhy.http.okhttp.OkHttpUtils; //导入依赖的package包/类
/**
* 获得主页的action
*/
private void historyInfo() {
OkHttpUtils.get().url(historyUrl)
.build()
.execute(new StringCallback() {
@Override
public void onError(Call call, Exception e) {
Toast.makeText(mContext, "数据初始化失败", Toast.LENGTH_SHORT).show();
}
@Override
public void onResponse(String response) {
mainAction = ParseHistoryInfo.getMainAction(response);
getHistoryHomePage();
}
});
}
示例14: getHistoryHomePage
import com.zhy.http.okhttp.OkHttpUtils; //导入依赖的package包/类
/**
* 获得查询的页面的action,以及查询条件
*/
private void getHistoryHomePage() {
OkHttpUtils.post().url(host + mainAction)
.addHeader("Host", "210.44.159.5")
.addHeader("Referer", historyUrl)
.addParams("account", account)
.addParams("inputObject", "15")
.addParams("Submit", "+%C8%B7+%B6%A8+")
.build()
.execute(new StringCallback() {
@Override
public void onError(Call call, Exception e) {
Toast.makeText(mContext, "关键信息获取失败", Toast.LENGTH_SHORT).show();
}
@Override
public void onResponse(String response) {
queryAction = ParseHistoryInfo.getQueryAction(response);
dayList = ParseHistoryInfo.getDayList(response);
dayList.add(3, "本月内");
}
});
}
示例15: queryHistoryMustInfo
import com.zhy.http.okhttp.OkHttpUtils; //导入依赖的package包/类
/**
* 获得等待页面的action
*/
private void queryHistoryMustInfo() {
OkHttpUtils.post().url(host + queryAction)
.addHeader("Host", "210.44.159.5")
.addHeader("Referer", host + mainAction)
.addParams("inputStartDate", inputStartDate)
.addParams("inputEndDate", inputEndDate)
// .addParams("__continue", cotinue)
.build()
.execute(new StringCallback() {
@Override
public void onError(Call call, Exception e) {
Toast.makeText(mContext, "链接获取失败", Toast.LENGTH_SHORT).show();
}
@Override
public void onResponse(String response) {
lastAction = ParseHistoryInfo.getLastAction(response);
queryHistoryConsumption();
}
});
}