use of retrofit2.Callback in project Gradle-demo by Arisono.
the class testUASApi method addWorkReport.
/**
* 添加日报
*/
public static void addWorkReport() {
String url = baseurl + "mobile/addWorkReport.action";
RequestBody formBody = new FormBody.Builder().add("master", master).add("formStore", "{\"wd_experience\":\"\",\"wd_comment\":\"13.37一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八\\n一二三\",\"wd_empcode\":\"U0747\",\"wd_plan\":\"\"}").add("caller", "WorkDaily").add("sessionId", sessionId).build();
Request request = new Request.Builder().url(url).header("cookie", "JSESSIONID=" + sessionId).addHeader("sessionUser", emcode).addHeader("content-type", "text/html;charset:utf-8").post(formBody).build();
OkhttpUtils.client.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
OkhttpUtils.println(OkhttpUtils.getResponseString(response));
}
@Override
public void onFailure(Call call, IOException e) {
OkhttpUtils.onFailurePrintln(e);
}
});
}
use of retrofit2.Callback in project Gradle-demo by Arisono.
the class testGithubApi method search_repositories.
/**
* 查询github repositories
*
*/
public static void search_repositories() {
search_repositories += "?q=" + q + "&sort=" + sort + "&order=" + order + "&page=" + page + "&per_page=" + per_page;
Request request = new Request.Builder().url(search_repositories).build();
OkhttpUtils.client.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
OkhttpUtils.println(OkhttpUtils.getResponseString(response));
OkhttpUtils.println(search_repositories);
}
@Override
public void onFailure(Call call, IOException e) {
OkhttpUtils.onFailurePrintln(e);
}
});
}
use of retrofit2.Callback in project Gradle-demo by Arisono.
the class OkhttpUtils method sendGetHttp.
/**
* get http
* @param url
* @param tag
*/
public static void sendGetHttp(String url, Map<String, Object> params, String cookies, String tag) {
StringBuilder buf = new StringBuilder(url);
if (params != null) {
if (!params.isEmpty()) {
if (url.indexOf("?") == -1)
buf.append("?");
else if (!url.endsWith("&"))
buf.append("&");
Iterator<Map.Entry<String, Object>> entries = params.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<String, Object> entry = entries.next();
buf.append(String.valueOf(entry.getKey())).append("=").append(String.valueOf(entry.getValue())).append("&");
}
buf.deleteCharAt(buf.length() - 1);
}
}
Request request = new Request.Builder().url(buf.toString()).addHeader("content-type", "text/html;charset:utf-8").addHeader("Cookie", "12").build();
OkhttpUtils.println(tag + ":" + buf.toString());
OkhttpUtils.client.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
String requestJson;
requestJson = OkhttpUtils.getResponseString(response);
OkhttpUtils.println(requestJson);
RxBus.getInstance().send(tag + ":" + requestJson);
}
@Override
public void onFailure(Call call, IOException e) {
OkhttpUtils.onFailurePrintln(call, e, this);
}
});
}
use of retrofit2.Callback in project BBS-Android by bdpqchen.
the class CollectionClient method loadCollection.
void loadCollection() {
Retrofit retrofit = new Retrofit.Builder().client(client).addConverterFactory(GsonConverterFactory.create()).baseUrl(RxDoHttpClient.BASE_URL + "home/").build();
CollectionApi collectionApi = retrofit.create(CollectionApi.class);
Call<CollectionBean> call = collectionApi.getCollection(uidToken);
call.enqueue(new Callback<CollectionBean>() {
@Override
public void onResponse(Call<CollectionBean> call, Response<CollectionBean> response) {
if (response != null) {
collectionPresenter.setCollectionDate(response.body());
}
}
@Override
public void onFailure(Call<CollectionBean> call, Throwable t) {
}
});
}
use of retrofit2.Callback in project BBS-Android by bdpqchen.
the class CollectionClient method collectByTid.
// TODO: 2017/5/23 传入Prenster来处理返回数据
void collectByTid(String tid) {
Retrofit retrofit = new Retrofit.Builder().client(client).addConverterFactory(GsonConverterFactory.create()).baseUrl("https://bbs.twtstudio.com/api/home/").build();
CollectionApi collectionApi = retrofit.create(CollectionApi.class);
Call<SimpleBean> call = collectionApi.collectByTid(uidToken, tid);
call.enqueue(new Callback<SimpleBean>() {
@Override
public void onResponse(Call<SimpleBean> call, Response<SimpleBean> response) {
collectionPresenter.dealCollectData(response.body());
}
@Override
public void onFailure(Call<SimpleBean> call, Throwable t) {
}
});
}
Aggregations