1. Add dependency: Compile ' com.zhy:okhttputils:2.6.2 '
2. Register initialization in the manifest file:
Initialize: okhttpclient okhttpclient = new Okhttpclient.builder ()
. Addinterceptor (New Loggerinterceptor ("TAG"))
. ConnectTimeout (10000L, Timeunit.milliseconds)
. ReadTimeout (10000L, Timeunit.milliseconds)
Other configurations
. build ();
Okhttputils.initclient (okhttpclient);
Get Request for 3.okhhtp-utils:
Okhttputils.get ()
. URL ("Http://apicloud.mob.com/boxoffice/day/query?key=1d120467e646b&area=CN")
. Build ()
. Execute (new Stringcallback () {
@Override
public void OnError (call call, Exception e, int id) {
}
@Override
public void Onresponse (String response, int id) {
}
});
4.okhhtp-utils POST Request:
Okhttputils.post ()
. URL ("Http://apicloud.mob.com/appstore/horoscope/day")
. Addparams ("date", year1)
. Addparams ("Hour", Day1)
. Addparams ("Key", "1d11949556a24")
. Build ()
. Execute (new Stringcallback () {
@Override
public void OnError (call call, Exception e, int id) {
}
@Override
public void Onresponse (String response, int id) {
LOG.D ("SSS", "Response:::" + response);
}
});
5.okhhtp-utils Loading Pictures:
Okhttputils.get ()
. URL ("Http://192.168.13.89:8080/Web_server/a.jpg")
. Build ()
. Execute (new Bitmapcallback () {
@Override
public void OnError (call call, Exception e, int id) {
}
@Override
public void Onresponse (BITMAP response, int id) {
Image.setimagebitmap (response);
}
});
Use of Okhttp-utils