在build.gradle
implementation 'com.squareup.okhttp3:okhttp:3.9.1'
implementation "com.squareup.okio:okio:2.10.0"
1.联网请求文本数据
2.大文件下载
3.大文件上传
4.请求图片
package com.example.testapplication;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import java.io.IOException;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class OkhttpActivity extends AppCompatActivity implements View.OnClickListener {
//配置编码
public static final MediaType JSON
= MediaType.
|