Android网络技术——HttpUrlConnection和OkHttp
- HttpURLConnection是一个abstract类,可用于发起网络请求
- OkHttp不仅在接口封装上做得简单易用,就连在底层实现上也是自成一派,比起原生的HttpURLConnection,可以说是有过之而无不及,现在已经成了广大Android开发者首选的网络通信库
一、布局设置
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_marginBottom="10dp">
<EditText
android:id="@+id/url"
android:layout_weight="7"
android:hint="请输入网址"
android:inputType="text"
android:layout_width="0dp"
android:layout_height="wrap_content" />