OkHttpClient client = new OkHttpClient();
Request build = new Request.Builder().url(url).build();
try {
<span style="white-space:pre"> </span>Response execute = client.newCall(build).execute();
if(execute.isSuccessful()){
System.out.println("wisely aaa");
} else {
System.out.println("wisely bbb");
}
} catch (IOException e) {
e.printStackTrace();
}
OkHttpClient client = new OkHttpClient();
Request build = new Request.Builder().url(url).build();
client.newCall(build).enqueue(new Callback() {
@Override
public void onResponse(Response arg0) throws IOException {
System.out.println("wisely success");
}
@Override
public void onFailure(Request arg0, IOException arg1) {
System.out.println("wisely failure");
}
});
OkHttpClient client = new OkHttpClient();
Request build = new Request.Builder().url(url).build();
client.newCall(build).enqueue(new Callback() {
@Override
public void onResponse(Response response) throws IOException {
// byte[] bytes = response.body().bytes();
InputStream is = response.body().byteStream();
Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
// Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length,options);
Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
Message msg = handler.obtainMessage();
msg.obj = bitmap;
handler.sendMessage(msg);
}
@Override
public void onFailure(Request arg0, IOException arg1) {
System.out.println("wisely fail:"+arg1.getCause().getMessage());
}
});
OkHttpClient client = new OkHttpClient();
RequestBody body = new FormEncodingBuilder()
.add("userName", "13363114390")
.add("password", "200820e3227815ed1756a6b531e7e0d2").build();
Request build = new Request.Builder().url(url).post(body).build();
client.newCall(build).enqueue(new Callback() {
@Override
public void onResponse(Response response) throws IOException {
String lenght = response.header("Content-Length");
System.out.println("wisely--lenght:" + lenght);
LoginResponse loginResponse = new Gson().fromJson(response.body().charStream(), LoginResponse.class);
System.out.println("wisely---" + loginResponse.getMessage());
}
@Override
public void onFailure(Request arg0, IOException arg1) {
System.out.println("wisely-----fail");
}
});
String tokeId;
boolean result;
public boolean isResult() {
return result;
}
public void setResult(boolean result) {
this.result = result;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getTokeId() {
return tokeId;
}
public void setTokeId(String tokeId) {
this.tokeId = tokeId;
}
}
private MediaType PNG = MediaType.parse("application/octet-stream");
OkHttpClient client = new OkHttpClient();
RequestBody body = new MultipartBuilder()
.type(MultipartBuilder.FORM)
.addPart(Headers.of("Content-Disposition","form-data; name=\"files\";filename=\"img1.jpg\""),RequestBody.create(PNG, file1))
.addPart(Headers.of("Content-Disposition","form-data; name=\"files\";filename=\"img2.jpg\""),RequestBody.create(PNG, file2)).build();
Request request = new Request.Builder()
<span style="white-space:pre"> </span>.url(url)
.post(body).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Response response) throws IOException {
if(response.isSuccessful()){
UploadPNGResponse uploadPNGResponse = new Gson().fromJson(response.body().charStream(), UploadPNGResponse.class);
String msg = uploadPNGResponse.getMsg();
List<String> list = uploadPNGResponse.getList();
for (String string : list) {
System.out.println("wisely---path:"+string);
}
}
}
@Override
public void onFailure(Request arg0, IOException arg1) {
System.out.println("wisely---fail--"+arg1.getCause().getMessage());
}
});
class UploadPNGResponse{
String msg;
boolean result;
List<String> list;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public boolean isResult() {
return result;
}
public void setResult(boolean result) {
this.result = result;
}
public List<String> getList() {
return list;
}
public void setList(List<String> list) {
this.list = list;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有