@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AsyncHttpClient client = new AsyncHttpClient();
String url = "https://hao.360.cn";
final TextView tv = (TextView)findViewById(R.id.st);
client.get(url, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
String result = new String(responseBody);
Log.e("result:",result);
tv.setText(result + "");
}

@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

}
});
}



<TextView
android:id="@+id/st"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />


implementation 'com.loopj.android:android-async-http:1.4.9'


posted on 2018-07-23 16:28  feixiang2018  阅读(116)  评论(0编辑  收藏  举报