美文网首页Android技术知识学习Android进阶之路
必须知道的Android网络框架大全!值得一看良心文章!

必须知道的Android网络框架大全!值得一看良心文章!

作者: cff70524f5cf | 来源:发表于2019-10-09 22:32 被阅读0次

    导语

    大通常在 Android 中进行网络连接一般使用 Scoket 和 HTTP两种方式。而 HTTP 请求方式比 Scoket 多得多,HTTP 请求一般采用原生的 HttpClient 和 HttpUrlConnection 的两种网络访问方式。可是在 Android 5.0 的时候 Google 就不推荐使用 HttpClient 了,到了 Android 6.0 (api 23) SDK,不再提供 org.apache.http.* (只保留几个类), 如果使用了 httpClient 相关类的库项目,如 android-async-http 等等,会出现有一些类找不到的错误。而从Android4.4开始HttpURLConnection的底层实现采用的是okHttp。

    okHttp、volley、android-async-http 对比如下:

    • volley是一个简单的异步http库,仅此而已。缺点是不支持同步,这点会限制开发模式;不能post大数据,不适合用来上传文件。
    • android-async-http。与volley一样是异步网络库,但volley是封装的httpUrlConnection,它是封装的httpClient,而android平台不推荐用HttpClient了,所以这个库已经不适合android平台了。
    • okhttp是高性能的http库,和volley一样实现了http协议的缓存,支持同步、异步,而且实现了spdy、http2、websocket协议,Api简洁易用。

    所以,还是okHttp 才是目前最值得推荐的一款网络通信框架,简洁易用,功能强大。但是,为了普及知识,还是要把曾经为Android效力过的网络请求方式都写出来。

    GitHub案例地址

    集成所有请求网络的方式及流行框架总结练习:该demo包含原生的HttpClient、HttpUrlConntection的网络请求方式。以及流行的框架如 :Volley、OkHttp、RxJava的练习。

    正文

    HttpUrlConnection

    最早学Android的时候用的网络请求是HttpUrlConnection,在android 2.2及以下版本中HttpUrlConnection存在着一些bug,所以建议在android 2.3以后使用HttpUrlConnection,之前使用HttpClient。在Android 2.2版本之前,HttpClient拥有较少的bug,因此使用它是最好的选择。而在Android 2.3版本及以后,HttpURLConnection则是最佳的选择。它的API简单,体积较小,因而非常适用于Android项目。压缩和缓存机制可以有效地减少网络访问的流量,在提升速度和省电方面也起到了较大的作用。对于新的应用程序应该更加偏向于使用HttpURLConnection,因为在以后的工作当中我们也会将更多的时间放在优化HttpURLConnection上面。

    特点:

    • 比较轻便,灵活,易于扩展。
    • 在3.0后以及4.0中都进行了改善,如对HTTPS的支持。
    • 在4.0中,还增加了对缓存的支持。

    使用:

    • 首先我们需要获取到一个HttpURLConnection实例,一般需要new出一个URL对象,并传入目标网络地址,通过调用openConnection()方法获得HttpURLConnection实例。
    • 得到该实例后。我们需要设置一下http请求的的方法,这里我们主要研究get和post,默认是使用get方法。get一般用于从服务器获取数据,post一般用于向服务器提交数据,设置请求方法使用函数setRequestMethod(“POST”)进行设置。
    • 此外可以进行一些请求的限制,比如连接超时的时间等,可以通过setConnectTimeout设置超时时间。
    • 获取服务器返回的输入流,使用getInputStream方法获取。
    • 读取内容并处理。
    • 关闭连接,通过调用disconnect方法关闭当前的连接。
    • 关键代码如下 。
    • 使用过程中不要忘记添加权限。
      <uses-permission android:name="android.permission.INTERNET"
    
    • GET
    public String get(String urlPath) {
            HttpURLConnection connection = null;
            InputStream is = null;
            try {
                URL url = new URL(urlPath);
                //获得URL对象
                connection = (HttpURLConnection) url.openConnection();
                //获得HttpURLConnection对象
                connection.setRequestMethod("GET");
                // 默认为GET
                connection.setUseCaches(false);
                //不使用缓存
                connection.setConnectTimeout(10000);
                //设置超时时间
                connection.setReadTimeout(10000);
                //设置读取超时时间
                connection.setDoInput(true);
                //设置是否从httpUrlConnection读入,默认情况下是true;
                if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                    //相应码是否为200
                    is = connection.getInputStream();
                    //获得输入流
                    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                    //包装字节流为字符流
                    StringBuilder response = new StringBuilder();
                    String line;
                    while ((line = reader.readLine()) != null) {
                        response.append(line);
                    }
                    return response.toString();
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (connection != null) {
                    connection.disconnect();
                    connection = null;
                }
                if (is != null) {
                    try {
                        is.close();
                        is = null;
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return null;
        }
    
    • POST
    private String post(String urlPath, Map<String, String> params) {
            if (params == null || params.size() == 0) {
                return get(urlPath);
            }
            OutputStream os = null;
            InputStream is = null;
            HttpURLConnection connection = null;
            StringBuffer body = getParamString(params);
            byte[] data = body.toString().getBytes();
            try {
                URL url = new URL(urlPath);
                //获得URL对象
                connection = (HttpURLConnection) url.openConnection();
                //获得HttpURLConnection对象
                connection.setRequestMethod("POST");
                // 设置请求方法为post
                connection.setUseCaches(false);
                //不使用缓存
                connection.setConnectTimeout(10000);
                //设置超时时间
                connection.setReadTimeout(10000);
                //设置读取超时时间
                connection.setDoInput(true);
                //设置是否从httpUrlConnection读入,默认情况下是true;
                connection.setDoOutput(true);
                //设置为true后才能写入参数
                connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                connection.setRequestProperty("Content-Length", String.valueOf(data.length));
                os = connection.getOutputStream();
                os.write(data);
                //写入参数
                if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                    //相应码是否为200
                    is = connection.getInputStream();
                    //获得输入流
                    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                    //包装字节流为字符流
                    StringBuilder response = new StringBuilder();
                    String line;
                    while ((line = reader.readLine()) != null) {
                        response.append(line);
                    }
                    return response.toString();
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                //关闭
                if (os != null) {
                    try {
                        os.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (connection != null) {
                    connection.disconnect();
                    connection = null;
                }
            }
            return null;
        }
     
        private StringBuffer getParamString(Map<String, String> params) {
            StringBuffer result = new StringBuffer();
            Iterator<Map.Entry<String, String>> iterator = params.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, String> param = iterator.next();
                String key = param.getKey();
                String value = param.getValue();
                result.append(key).append('=').append(value);
                if (iterator.hasNext()) {
                    result.append('&');
                }
            }
            return result;
        }
    

    HttpClient

    简述

    高效稳定,但是维护成本高昂,故开发团队不愿意维护该库而是转投更为轻便的HttpUrlConnection。

    用法

    1.HttpClient是一个接口,因此无法直接创建它的实例,一般都是创建一个DefaultHttpClient实例。
    2.如果要发起Get请求,需要创建一个HttpGet对象,并传入请求地址。
    3.如果要发起Post请求,需要创建一个HttpPost对象。并传入请求地址,通过setEntity函数设置请求参数。
    4.调用execute方法,传入HttpGet或者HttpPost实例,执行后返回HttpResponse对象,判断响应状态码。

    解析响应结果,通过调用getEntity函数获得一个HttpEntity对象,之后可以通过EntityUtils.toString方法将其转换为字符串。

    由于在android2.3之后就被HttpUrlConnection取代了,这里也不过多介绍了,不过当初学习它的时候还没接触到其他库。

    下面是使用GET方法:

    privateString get(String url){        
        HttpClient client=null;        
        HttpGet request=null;try{            
        client=newDefaultHttpClient();            
        request=newHttpGet(url);            
        HttpResponse response=client.execute(request);
        if(response.getStatusLine().getStatusCode()==HttpStatus.SC_OK){   
                 String result=EntityUtils.toString(response.getEntity(),"UTF-8");returnresult;        
            }     
         }catch(IOException e) {   
              e.printStackTrace();   
           }returnnull;  
      }
    

    特点

    1.所以请求在子线程中完成,请求回调在调用该请求的线程中完成;
    2.使用线程池;
    3.使用RequestParams类封装请求参数;
    4.支持文件上传;
    5.持久化cookie到SharedPreferences,个人感觉这一点也是这个库的重要特点,可以很方便的完成一些模拟登录;
    6.支持json;
    7.支持HTTP Basic Auth;

    用法

    编写一个静态的HttpClient

    package cn.edu.zafu.http;
     
    import com.loopj.android.http.AsyncHttpClient;
    import com.loopj.android.http.AsyncHttpResponseHandler;
    import com.loopj.android.http.RequestParams;
    /**
     * Created by lizhangqu on 2015/5/7.
     */
    public class TestClient {
        private static final String BASE_URL = "http://121.41.119.107/";
     
        private static AsyncHttpClient client = new AsyncHttpClient();
     
        public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
            client.get(getAbsoluteUrl(url), params, responseHandler);
        }
     
        public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
            client.post(getAbsoluteUrl(url), params, responseHandler);
        }
     
        private static String getAbsoluteUrl(String relativeUrl) {
            return BASE_URL + relativeUrl;
        }
    } 
    
    • 调用get或者post方法

    参数通过RequestParams传递,没有参数则传递null

    RequestParams  params = new RequestParams();
    params.put("","");
    
    • 如果要保存cookie,在发起请求之前调用以下代码
    PersistentCookieStore myCookieStore = new PersistentCookieStore(this);
    client.setCookieStore(myCookieStore);
    

    之后请求所得到的cookie都会自动持久化;如果要自己添加cookie,则调用以下代码

    BasicClientCookie newCookie = new BasicClientCookie("cookiesare", "awesome");
    newCookie.setVersion(1);
    newCookie.setDomain("mydomain.com");
    newCookie.setPath("/");
    myCookieStore.addCookie(newCookie);
    
    • 在回调函数中处理返回结果
    private void get(){
            TestClient.get("test/index.php", null, new AsyncHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
     
                }
     
                @Override
                public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
     
                }
            });
        }
        private void post(){
            RequestParams params = new RequestParams();
            params.put("user","asas");
            params.put("pass","12121");
            params.put("time","1212121");
            TestClient.post("test/login.php", params, new AsyncHttpResponseHandler() {
                @Override
                public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
     
                }
     
                @Override
                public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
     
                }
            });
        }
    

    Volley

    既然在android2.2之后不建议使用Http Client,那么有没有一个库是android2.2及以下版本使用Http Client,而android2.3及以上版本使用HttpUrlConnection的呢,答案是肯定的,就是Volley,它是android开发团队在2013年Google I/O大会上推出了一个新的网络通信框架。

    Volley可以说是把AsyncHttpClient和Universal-Image-Loader的优点集于了一身,既可以像AsyncHttpClient一样非常简单地进行HTTP通信,也可以像Universal-Image-Loader一样轻松加载网络上的图片。除了简单易用之外,Volley在性能方面也进行了大幅度的调整,它的设计目标就是非常适合去进行数据量不大,但通信频繁的网络操作,而对于大数据量的网络操作,比如说下载文件等,Volley的表现就会非常糟糕。

    特点

    • Volley的优势在于处理小文件的http请求;
    • 在Volley中也是可以使用Okhttp作为传输层
    • Volley在处理高分辨率的图像压缩上有很好的支持;
    • NetworkImageView在GC的使用模式上更加保守,在请求清理上也更加积极,networkimageview仅仅依赖于强大的内存引用,并当一个新请求是来自ImageView或ImageView离开屏幕时 会清理掉所有的请求数据。

    用法

    1.创建一个RequestQueue对象。
    2.创建一个Request对象。
    3.将Request对象添加到RequestQueue里面。
    4.下面一步一步来学习其用法

    GET

     private void get(){
            RequestQueue queue= Volley.newRequestQueue(getApplicationContext());
            String url="http://121.41.119.107/test/index.php";
            StringRequest request=new StringRequest(url, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.d("TAG",response);
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
     
                }
            });
            queue.add(request);
        }
    

    **POST **
    通过指定请求方法为Request.Method.POST使其成为post请求,然后重新getParams方法设置请求参数。当发出POST请求的时候,Volley会尝试调用StringRequest的父类——Request中的getParams()方法来获取POST参数

    private void post() {
            RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
            String url = "http://121.41.119.107/test/login.php";
            StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.d("TAG", response);
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
     
                }
            }) {
                //重写getParams方法设置参数
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("user", "asas");
                    params.put("pass", "12121");
                    params.put("time", "1212121");
                    return params;
                }
            };
            queue.add(request);
        }
    

    加载图像的方法和前面类似,只不过不在是StringRequest而是ImageRequest。

    private void getImage() {
            RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
            String url = "https://www.baidu.com/img/bdlogo.png";
            //第三第四个参数分别用于指定允许图片最大的宽度和高度,如果指定的网络图片的宽度或高度大于这里的最大值,则会对图片进行压缩,指定成0的话就表示不管图片有多大,都不会进行压缩。
            //第五个参数就是ImageView里中的属性ScaleType
            //第六个参数用于指定图片的颜色属性
            ImageRequest request = new ImageRequest(url, new Response.Listener<Bitmap>() {
                @Override
                public void onResponse(Bitmap response) {
                    ImageView iv= (ImageView) findViewById(R.id.iv);
                    iv.setImageBitmap(response);
                }
            }, 0, 0, ImageView.ScaleType.CENTER, Bitmap.Config.ARGB_8888, new Response.ErrorListener() {
     
                @Override
                public void onErrorResponse(VolleyError error) {
     
                }
            });
            queue.add(request);
        }
    

    其实加载图片的功能还远远不止这些,使用ImageLoader可以实现对图片的缓存,还可以过滤重复链接,避免发送重复的请求
    ImageLoader的使用方法概括为以下几步

    1. 创建一个RequestQueue对象。
    2. 创建一个ImageLoader对象。
    3. 获取一个ImageListener对象。
    4. 调用ImageLoader的get()方法加载网络上的图片。
    //继承ImageCache,使用LruCache实现缓存
        public class BitmapCache implements ImageLoader.ImageCache {
            private LruCache<String, Bitmap> mCache;
            public BitmapCache() {
                int maxSize = 10 * 1024 * 1024;
                mCache = new LruCache<String, Bitmap>(maxSize) {
                    @Override
                    protected int sizeOf(String key, Bitmap bitmap) {
                        return bitmap.getRowBytes() * bitmap.getHeight();
                    }
                };
            }
            @Override
            public Bitmap getBitmap(String url) {
                return mCache.get(url);
            }
            @Override
            public void putBitmap(String url, Bitmap bitmap) {
                mCache.put(url, bitmap);
            }
     
        }
        private void getImageByImageLoader() {
            ImageView iv= (ImageView) findViewById(R.id.iv);
            RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
            String url = "https://www.baidu.com/img/bdlogo.png";
            ImageLoader loader=new ImageLoader(queue,new BitmapCache() );
            // 第一个参数指定用于显示图片的ImageView控件
            // 第二个参数指定加载图片的过程中显示的图片
            // 第三个参数指定加载图片失败的情况下显示的图片
            ImageLoader.ImageListener listener=ImageLoader.getImageListener(iv,R.mipmap.ic_launcher,R.mipmap.ic_launcher);
            // 调用ImageLoader的get()方法来加载图片
            // 第一个参数就是图片的URL地址
            // 第二个参数则是刚刚获取到的ImageListener对象
            // 如果想对图片的大小进行限制,也可以使用get()方法的重载,指定图片允许的最大宽度和高度,即通过第三第四个参数指定
            loader.get(url,listener);
        }
    

    OkHttp

    简述

    是一个 Java 的 HTTP+SPDY 客户端开发包,同时也支持 Android。需要Android 2.3以上。

    特点

    • OKHttp是Android版Http客户端。非常高效,支持SPDY、连接池、GZIP和 HTTP 缓存。
    • 默认情况下,OKHttp会自动处理常见的网络问题,像二次连接、SSL的握手问题。
    • 如果你的应用程序中集成了OKHttp,Retrofit默认会使用OKHttp处理其他网络层请求。
    • 从Android4.4开始HttpURLConnection的底层实现采用的是okHttp.

    用法

    1.新建一个OkHttpClient对象
    2.通过Request.Builder对象新建一个Request对象
    3.返回执行结果

    • GET
    private String get(String url) {
            OkHttpClient client = new OkHttpClient();
            Request request = new Request.Builder()
                    .url(url)
                    .build();
            Response response = null;
            try {
                response = client.newCall(request).execute();
                return response.body().string();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    
    • POST
      POST需要使用RequestBody对象,之后再构建Request对象时调用post函数将其传入即可
    private String post(String url) {
            OkHttpClient client = new OkHttpClient();
     
            RequestBody formBody = new FormEncodingBuilder()
                    .add("user", "Jurassic Park")
                    .add("pass", "asasa")
                    .add("time", "12132")
                    .build();
            Request request = new Request.Builder()
                    .url(url)
                    .post(formBody)
                    .build();
            Response response = null;
            try {
                response = client.newCall(request).execute();
                return response.body().string();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    

    此外,post的使用方法还支持文件等操作,具体使用方法有兴趣的可以自行查阅

    • 对Gson的支持
    private Person gson(String url){
            OkHttpClient client = new OkHttpClient();
            Gson gson = new Gson();
            Request request = new Request.Builder()
                    .url(url)
                    .build();
            Response response = null;
            try {
                response = client.newCall(request).execute();
                Person person = gson.fromJson(response.body().charStream(), Person.class);
                return person;
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    
    • 异步操作
      以上的两个例子必须在子线程中完成,同时okHttp还提供了异步的方法调用,通过使用回调来进行异步调用,然后okHttp的回调依然不在主线程中,因此该回调中不能操作UI
    private void getAsync(String url) {
            OkHttpClient client = new OkHttpClient();
            Request request = new Request.Builder()
                    .url(url)
                    .build();
            Response response = null;
     
            client.newCall(request).enqueue(new Callback() {
                @Override
                public void onFailure(Request request, IOException e) {
     
                }
     
                @Override
                public void onResponse(Response response) throws IOException {
                    String result = response.body().string();
                    Toast.makeText(getApplicationContext(),result,Toast.LENGTH_SHORT).show();
                    //不能操作ui,回调依然在子线程
                    Log.d("TAG", result);
                }
            });
        }
    

    okHttp的使用还有很多内容,这里也不过多介绍,更多内容,参考官方网址

    Retrofit

    特点

    1.性能最好,处理最快
    2.使用REST API时非常方便;
    3.传输层默认就使用OkHttp;
    4.支持NIO;
    5.拥有出色的API文档和社区支持
    6.速度上比volley更快;
    7.如果你的应用程序中集成了OKHttp,Retrofit默认会使用OKHttp处理其他网络层请求。
    8.默认使用Gson

    使用
    Retrofit支持同步和异步两种方式,在使用时,需要将请求地址转换为接口,通过注解来指定请求方法,请求参数,请求头,返回值等信息。还是使用之前的person的那段json值,get请求到服务器后从数据库查询数据,返回值为查询到的数据,post请求向服务器提交一条数据,返回值为提交的数据。

    首先,完成请求所用的service,是一个interface,完全通过注解完成配置

    package cn.edu.zafu.http;
     
    import retrofit.Callback;
    import retrofit.http.Field;
    import retrofit.http.FormUrlEncoded;
    import retrofit.http.GET;
    import retrofit.http.Headers;
    import retrofit.http.POST;
    import retrofit.http.Path;
    import retrofit.http.Query;
     
    /**
     * Created by lizhangqu on 2015/5/11.
     */
    public interface PersonService {
        @Headers({
                "Cache-Control: max-age=640000",
                "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
        })
        //通过注解设置请求头
        @GET("/{test}/rest.php")
        //设置请求方法为get,相对路径为注解内内容,其中{test}会被@Path注解指定内容替换
        Person getPerson(@Path("test") String dir,@Query("name") String name);
        //@Query用于指定参数
     
        @FormUrlEncoded
        //urlencode
        @POST("/test/rest1.php")
        //post提交
        Person updatePerson(@Field("name") String name,@Field("age") int age);
        //@Field提交的域
     
     
        @POST("/test/rest1.php")
        void updatePerson(@Field("name") String name,@Field("age") int age, Callback<Person> callback);
        //异步回调,不能指定返回值
    } 
    
    • GET

    使用时,通过RestAdapter的实例获得一个接口的实例,其本质是动态代理,注意含有返回值的方法是同步的,不能UI线程中调用,应该在子线程中完成

    RestAdapter restAdapter = new RestAdapter.Builder()
                            .setEndpoint("http://121.41.119.107")
                            .build();
                    PersonService personService=restAdapter.create(PersonService.class);
                    Person person=personService.getPerson("test","zhangsan");
                    Log.d("TAG",person.toString());
    
    • POST

    POST的调用同Get,获得adapter后获得一个代理对象,然后通过这个代理对象进行网络请求

    Person person1=personService.updatePerson("lizhangqu", 12);
    Log.d("TAG",person1.toString());
    
    • 异步请求

    如果要使用异步请求,需要将接口中的方法返回值修改会void,再加入回调参数Callback,就如PersonService中第三个方法一样,请求完成后会回调该callback对象的success或者fail方法。

    RestAdapter restAdapter = new RestAdapter.Builder()
                    .setEndpoint("http://121.41.119.107")
                    .build();
            PersonService personService=restAdapter.create(PersonService.class);
            personService.updatePerson("lizhangqu",23, new Callback<Person>() {
                @Override
                public void success(Person person, Response response) {
                    Log.d("TAG", person.toString());
                }
     
                @Override
                public void failure(RetrofitError error) {
     
                }
            }); 
    

    Retrofit的使用还有很多内容,剩下的就留给各位读者自行去发现了,而其官网页提供了及其详细的说明。retrofit官网示例

    这个库里面有很多精华的内容,建议各位仔细的阅读下官方的文档。

    好了,文章到这里就结束了,如果你觉得文章写得不错就给个赞呗?如果你觉得那里值得改进的,请给我留言。一定会认真查询,修正不足。谢谢。

    最后这里是关于我自己的Android 学习,面试文档,视频收集大整理,有兴趣的伙伴们可以看看~

    如果你觉得还算有用的话,不妨把它们推荐给你的朋友。

    相关文章

      网友评论

        本文标题:必须知道的Android网络框架大全!值得一看良心文章!

        本文链接:https://www.haomeiwen.com/subject/tfynpctx.html