根据安卓第一行代码Okhttp3第一次使用报错
2020-04-07 本文已影响0人
deanwin
private void sedRwq1() {
new Thread(new Runnable(){
public void run() {
try {
String url ="https://wwww.baidu.com";
OkHttpClient okHttpClient =new OkHttpClient();
final Request request =new Request.Builder()
.url(url)
.get()//默认就是GET请求,可以不写
.build();
Response response = okHttpClient.newCall(request).execute();
String responseData =response.body().string();
showResponse(responseData);
}catch (MalformedURLException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
1.可能报错 No Network Security Config specified, using platform default
替换成这个在Manifest里的application标签加上一条 android:usesCleartextTraffic="true" 就可以了