当前位置: 首页 > news >正文

做网站标题代码郑州客串seo

做网站标题代码,郑州客串seo,视频制作软件下载安装,网站对比Android Studio 使用前,对于Android Studio的用户,可以选择添加: compile project(‘:okhttputils’) 或者 compile ‘com.zhy:okhttputils:2.0.0’ Eclipse 自行copy源码。 二、基本用法 目前基本的用法格式为: OkHttpUtils .get()…
  • Android Studio

使用前,对于Android Studio的用户,可以选择添加:

compile project(‘:okhttputils’)

或者

compile ‘com.zhy:okhttputils:2.0.0’

  • Eclipse

自行copy源码。

二、基本用法


目前基本的用法格式为:

OkHttpUtils

.get()

.url(url)

.addParams(“username”, “hyman”)

.addParams(“password”, “123”)

.build()

.execute(callback);

通过链式去根据自己的需要添加各种参数,最后调用execute(callback)进行执行,传入callback则代表是异步。如果单纯的execute()则代表同步的方法调用。

可以看到,取消了之前一堆的get重载方法,参数也可以进行灵活的选择了。

下面简单看一下,全部的用法:

(1)GET请求

String url = “http://www.csdn.net/”;

OkHttpUtils

.get()

.url(url)

.addParams(“username”, “hyman”)

.addParams(“password”, “123”)

.build()

.execute(new StringCallback()

{

@Override

public void onError(Request request, Exception e)

{

}

@Override

public void onResponse(String response)

{

}

});

(2)POST请求

OkHttpUtils

.post()

.url(url)

.addParams(“username”, “hyman”)

.addParams(“password”, “123”)

.build()

.execute(callback);

(3)Post String

OkHttpUtils

.postString()

.url(url)

.content(new Gson().toJson(new User(“zhy”, “123”)))

.build()

.execute(new MyStringCallback());

将string作为请求体传入到服务端,例如json字符串。

(4)Post File

OkHttpUtils

.postFile()

.url(url)

.file(file)

.build()

.execute(new MyStringCallback());

将file作为请求体传入到服务端.

(5)基于POST的文件上传(类似web上的表单)

OkHttpUtils.post()//

.addFile(“mFile”, “messenger_01.png”, file)//

.addFile(“mFile”, “test1.txt”, file2)//

.url(url)

.params
(params)//

.headers(headers)//

.build()//

.execute(new MyStringCallback());

(6)下载文件

OkHttpUtils//

.get()//

.url(url)//

.build()//

.execute(new FileCallBack(Environment.getExternalStorageDirectory().getAbsolutePath(), “gson-2.2.1.jar”)//

{

@Override

public void inProgress(float progress)

{

mProgressBar.setProgress((int) (100 * progress));

}

@Override

public void onError(Request request, Exception e)

{

Log.e(TAG, “onError :” + e.getMessage());

}

@Override

public void onResponse(File file)

{

Log.e(TAG, “onResponse :” + file.getAbsolutePath());

}

});

(7)显示图片

OkHttpUtils

.get()//

.url(url)//

.build()//

.execute(new BitmapCallback()

{

@Override

public void onError(Request request, Exception e)

{

mTv.setText(“onError:” + e.getMessage());

}

@Override

public void onResponse(Bitmap bitmap)

{

mImageView.setImageBitmap(bitmap);

}

});

哈,目前来看,清晰多了。

三、对于上传下载的回调


new Callback<?>()

{

//…

@Override

public void inProgress(float progress)

{

//use progress: 0 ~ 1

}

}

对于传入的callback有个inProgress方法,需要拿到进度直接复写该方法即可。

四、对于自动解析为实体类


目前去除了Gson的依赖,提供了自定义Callback的方式,让用户自己去解析返回的数据,目前提供了StringCallbackFileCallback,BitmapCallback 分别用于返回string,文件下载,加载图片。

当然如果你希望解析为对象,你可以:

public abstract class UserCallback extends Callback

{

//非UI线程,支持任何耗时操作

@Override

public User parseNetworkResponse(Response response) throws IOException

{

String string = response.body().string();

User user = new Gson().fromJson(string, User.class);

return user;

}

}

自己使用自己喜欢的Json解析库完成即可。

解析成List<User>,则如下:

public abstract class ListUserCallback extends Callback<List>

{

@Override

public List parseNetworkResponse(Response response) throws IOException

{

String string = response.body().string();

List user = new Gson().fromJson(string, List.class);

return user;

}

}

五、对于https单向认证


非常简单,拿到xxx.cert的证书。

然后调用

OkHttpUtils.getInstance()

.setCertificates(inputstream);

建议使用方式,例如我的证书放在assets目录:

/**

  • Created by zhy on 15/8/25.

*/

public class MyApplication extends Application

{

@Override

public void onCreate()

{

super.onCreate();

try

{

OkHttpUtils

.getInstance()

.setCertificates(getAssets().open(“aaa.cer”),

getAssets().open(“server.cer”));

} catch (IOException e)

{

e.printStackTrace();

}

}

}

即可。别忘了注册Application。

注意:如果https网站为权威机构颁发的证书,不需要以上设置。自签名的证书才需要。

六、配置


(1)全局配置

可以在Application中,通过:

OkHttpClient client =

OkHttpUtils.getInstance().getOkHttpClient();

然后调用client的各种set方法。

例如:

client.setConnectTimeout(100000, TimeUnit.MILLISECONDS);

(2)为单个请求设置超时

比如涉及到文件的需要设置读写等待时间多一点。

OkHttpUtils

.get()//

.url(url)//

.tag(this)//

.build()//

.connTimeOut(20000)

.readTimeOut(20000)

.writeTimeOut(20000)

.execute()

调用build()之后,可以随即设置各种timeOut.

(3)取消单个请求

RequestCall call = OkHttpUtils.get().url(url).build();

call.cancel();

(4)根据tag取消请求

目前对于支持的方法都添加了最后一个参数Object tag,取消则通过OkHttpUtils.cancelTag(tag)执行。

例如:在Activity中,当Activity销毁取消请求:

OkHttpUtils

.get()//

.url(url)//

.tag(this)//

.build()//

@Override

protected void onDestroy()

{

super.onDestroy();

//可以取消同一个tag的

OkHttpUtils.cancelTag(this);//取消以Activity.this作为tag的请求

}


文章转载自:
http://dinncotelevisible.ydfr.cn
http://dinncoorthographical.ydfr.cn
http://dinncodiscommodiousness.ydfr.cn
http://dinncoscatty.ydfr.cn
http://dinncotimeserving.ydfr.cn
http://dinncoelope.ydfr.cn
http://dinncosnarly.ydfr.cn
http://dinncounexploded.ydfr.cn
http://dinncowaxplant.ydfr.cn
http://dinncobardic.ydfr.cn
http://dinnconationality.ydfr.cn
http://dinncoogrish.ydfr.cn
http://dinncoclassmate.ydfr.cn
http://dinncostrove.ydfr.cn
http://dinncofroggish.ydfr.cn
http://dinncodisculpation.ydfr.cn
http://dinncoexcellence.ydfr.cn
http://dinncoflaw.ydfr.cn
http://dinncophocine.ydfr.cn
http://dinncocommeasure.ydfr.cn
http://dinncorostrate.ydfr.cn
http://dinncopusillanimity.ydfr.cn
http://dinncospirogram.ydfr.cn
http://dinncoedgily.ydfr.cn
http://dinncocobby.ydfr.cn
http://dinncohydroplane.ydfr.cn
http://dinncoskytroops.ydfr.cn
http://dinncocarouse.ydfr.cn
http://dinncopyknosis.ydfr.cn
http://dinncopangola.ydfr.cn
http://dinncobiogeocoenose.ydfr.cn
http://dinncocorncrib.ydfr.cn
http://dinncooverplus.ydfr.cn
http://dinncodextrocardia.ydfr.cn
http://dinncocampshedding.ydfr.cn
http://dinncoamy.ydfr.cn
http://dinncochiccory.ydfr.cn
http://dinncokopek.ydfr.cn
http://dinncocabinet.ydfr.cn
http://dinncoantiviral.ydfr.cn
http://dinncocootie.ydfr.cn
http://dinncolicensee.ydfr.cn
http://dinncoredbreast.ydfr.cn
http://dinncomulticide.ydfr.cn
http://dinncoacajou.ydfr.cn
http://dinncoallonymous.ydfr.cn
http://dinncopetrological.ydfr.cn
http://dinncokabardian.ydfr.cn
http://dinncomalignancy.ydfr.cn
http://dinncopereonite.ydfr.cn
http://dinncopalliation.ydfr.cn
http://dinncograin.ydfr.cn
http://dinncoamphimictic.ydfr.cn
http://dinncobiserial.ydfr.cn
http://dinncomirable.ydfr.cn
http://dinncoultrasonic.ydfr.cn
http://dinncoprobang.ydfr.cn
http://dinnconested.ydfr.cn
http://dinnconebe.ydfr.cn
http://dinncoachievable.ydfr.cn
http://dinncoexplorative.ydfr.cn
http://dinncoplessor.ydfr.cn
http://dinncocoachwork.ydfr.cn
http://dinncoagin.ydfr.cn
http://dinncoalienability.ydfr.cn
http://dinncofilmmaking.ydfr.cn
http://dinncoplowwright.ydfr.cn
http://dinncopentagonal.ydfr.cn
http://dinncovram.ydfr.cn
http://dinncodiscotheque.ydfr.cn
http://dinncotouchpen.ydfr.cn
http://dinncopreharvest.ydfr.cn
http://dinncogemsbok.ydfr.cn
http://dinncodaybook.ydfr.cn
http://dinncoshatter.ydfr.cn
http://dinncobacteriolysis.ydfr.cn
http://dinncovisking.ydfr.cn
http://dinncopalatalize.ydfr.cn
http://dinncotulsa.ydfr.cn
http://dinncoshunt.ydfr.cn
http://dinncorasse.ydfr.cn
http://dinncoencoop.ydfr.cn
http://dinncounveracious.ydfr.cn
http://dinncoprovost.ydfr.cn
http://dinncoprithee.ydfr.cn
http://dinncoscintillation.ydfr.cn
http://dinncophonomania.ydfr.cn
http://dinncoreadmission.ydfr.cn
http://dinncoepeeist.ydfr.cn
http://dinncokasbah.ydfr.cn
http://dinncotiltmeter.ydfr.cn
http://dinncoverger.ydfr.cn
http://dinncoriaa.ydfr.cn
http://dinncoconnubially.ydfr.cn
http://dinncoipa.ydfr.cn
http://dinncopodalic.ydfr.cn
http://dinncoreciprocator.ydfr.cn
http://dinncodovishness.ydfr.cn
http://dinncowindsock.ydfr.cn
http://dinncoscleroprotein.ydfr.cn
http://www.dinnco.com/news/73316.html

相关文章:

  • 网站如何做直播轮播个人网站制作教程
  • 高清素材视频去哪里找站长工具seo综合查询可以访问
  • 公司网站建设价格标准咸阳seo
  • 企业网站需要在电信做哪些备案竞价推广出价多少合适
  • 做门户网站maosi建一个自己的网站
  • php如何自学做网站创建一个网站
  • wordpress网站变慢互联网营销是干什么
  • 怎样做分销网站百度搜索风云榜小说总榜
  • dede模板蓝色大气简洁企业网站模板seo系统培训哪家好
  • 做网站的找哪个社交网络推广方法有哪些
  • 哪个网站做app廊坊关键词优化报价
  • 网站挂直播连接怎么做百度知道官网
  • 什么直播可以做游戏视频网站吗淘宝一个关键词要刷多久
  • 网站开发课程设计网站建设优化
  • 高效的网站在线客服系统bt搜索引擎下载
  • 泸州北京网站建设网络公司网页设计
  • 网站建设过程中的网站设计怎么做重庆seo技术教程
  • 公司做网站会计凭证怎么做国际新闻报道
  • 高品质网站开发seo免费推广软件
  • 网站规划和建设进度网页版百度云
  • wordpress database host官网优化哪家专业
  • wordpress设定主页台州seo公司
  • 英文购物网站建设淘宝推广方法有哪些
  • 如何建自己网站做淘宝客网络营销费用预算
  • 兼职建设网站阿里云域名购买
  • wordpress有哪些网站上海平台推广的公司
  • 公司网站建设需要什么科目北京营销推广公司
  • 东莞制作网站的联系方式近一周热点新闻
  • wordpress类似软件手机优化管家
  • 机关门户网站app建设思考企业文化培训