Android OkHttp网络请求 get 和 post (带Token)
例:(打印)
依赖:
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.2'
compile 'net.qiujuer.common:okhttp:3.0.0'
compile 'com.google.code.gson:gson:2.2.4'
/**
* Android OkHttp网络请求
* get 和 post (带Token)
*/
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setget();
setpost();
}
/**
* post请求
* http://www.lygjjdj.com:82/HZZHDJ/api/base64Upload.do?base64String=data:image/png;base64,......
* token : 2413a775f7d3fcfa0ebb625ac4e8ac35
*/
public void setpost() {
//post请求 传参
// FormBody formBody = new FormBody.Builder()
// .add("base64String","data:image/png;base64,"+imgStr)
// .add("id","15")
// .add("name","这是")
// .build();
Request request = new Request.Builder()
// .url("http://www.lygjjdj.com:82/HZZHDJ/api/base64Upload.do")
.url("ht