//Get请求
OkHttpClient mOkHttpClient = new OkHttpClient();
final Request request = new Request.Builder().url("http://qxu1649250094.my3w.com/ssuo.php?ssuo=").build();
Call call = mOkHttpClient.newCall(request);
call.enqueue(new com.squareup.okhttp.Callback() {
@Override
public void onFailure(Request request, IOException e) {
}
@Override
public void onResponse(Response response) throws IOException {
}
});
//POST请求
OkHttpClient mOkHttpClient = new OkHttpClient();
FormEncodingBuilder builder=new FormEncodingBuilder();
builder.add("Table","sview1").add("Pass","123");
RequestBody body=builder.build();
final Request request = new Request.Builder().url("http://qxu1649250094.my3w.com/ssuo.php?ssuo=").post(body).build();
Call call = mOkHttpClient.newCall(request);
call.enqueue(new com.squareup.okhttp.Callback() {
@Override
public void onFailure(Request request, IOException e) {
}
@Override
public void onResponse(Response response) throws IOException {
}
});
//文件下载
OkHttpClient mOkHttpClient = new OkHttpClient();
final Request request = new Request.Builder().url("http://qxu1649250094.my3w.com/user.exe").build();
Call call = mOkHttpClient.newCall(request);
call.enqueue(new com.squareup.okhttp.Callback() {
@Override
public void onFailure(Request request, IOException e) {
}
@Override
public void onResponse(Response response) throws IOException {
byte[] bytes = new byte[8*1024];
inputStream = response.body().byteStream();
fos = openFileOutput("QQ.exe", MODE_APPEND);
while ((length = inputStream.read(bytes)) != -1) {
fos.write(bytes, 0, length);
}
fos.flush();
if (inputStream != null) {
inputStream.close();
}
if (fos != null) {
fos.close();
}
}
});
转载请注明原文地址: https://ju.6miu.com/read-1000073.html