|
|
|
|
@ -1,61 +1,79 @@
|
|
|
|
|
//Copyright (c) 2017. 章钦豪. All rights reserved.
|
|
|
|
|
//定义包名,表明该接口属于 "monkeybook" 项目中的 API 部分
|
|
|
|
|
package com.monke.monkeybook.common.api;
|
|
|
|
|
//引入所需的库
|
|
|
|
|
import io.reactivex.Observable; //引入RxJava中的Observable,用于定义响应式流
|
|
|
|
|
import retrofit2.http.Field; //引入Retrofit中的@Field 注解,用于表示POST请求中的表单字段
|
|
|
|
|
import retrofit2.http.FormUrlEncoded; //引入Retrofit中的@FormUrlEncoded注解,用于标记表单请求
|
|
|
|
|
import retrofit2.http.GET; //引入Retrofit中的@GET注解,用于定义GET请求
|
|
|
|
|
import retrofit2.http.Headers; //引入Retrofit中的@Headers注解,用于添加HTTP请求头
|
|
|
|
|
import retrofit2.http.Query; //引入Retrofit中的@Query注解,用于在URL中添加查询参数
|
|
|
|
|
import retrofit2.http.Url; //引入Retrofit中的@Url注解,用于动态传递URL
|
|
|
|
|
|
|
|
|
|
import io.reactivex.Observable;
|
|
|
|
|
import retrofit2.http.Field;
|
|
|
|
|
import retrofit2.http.FormUrlEncoded;
|
|
|
|
|
import retrofit2.http.GET;
|
|
|
|
|
import retrofit2.http.Headers;
|
|
|
|
|
import retrofit2.http.Query;
|
|
|
|
|
import retrofit2.http.Url;
|
|
|
|
|
|
|
|
|
|
//该API接口定义了与小说网站进行交互的方法,用于获取书籍信息、搜索书籍、获取书籍内容等。
|
|
|
|
|
public interface IGxwztvApi {
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
|
|
|
|
|
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
|
|
|
|
|
"Accept-Charset:UTF-8",
|
|
|
|
|
"Connection:close",
|
|
|
|
|
"Cache-Control:no-cache"})
|
|
|
|
|
//获取书籍信息的请求
|
|
|
|
|
@GET //定义GET请求
|
|
|
|
|
//设置请求头
|
|
|
|
|
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //设置请求头:接受的响应类型
|
|
|
|
|
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent,模拟浏览器请求
|
|
|
|
|
"Accept-Charset:UTF-8", //设置字符集为 UTF-8
|
|
|
|
|
"Connection:close", //请求头:请求完成后关闭连接
|
|
|
|
|
"Cache-Control:no-cache"}) //禁用缓存
|
|
|
|
|
//该方法接收一个动态URL,返回Observable<String>,表示异步的响应数据流
|
|
|
|
|
Observable<String> getBookInfo(@Url String url);
|
|
|
|
|
|
|
|
|
|
@GET("/search.htm")
|
|
|
|
|
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
|
|
|
|
|
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
|
|
|
|
|
"Accept-Charset:UTF-8",
|
|
|
|
|
"Connection:close",
|
|
|
|
|
"Cache-Control:no-cache"})
|
|
|
|
|
//搜索书籍的请求
|
|
|
|
|
@GET("/search.htm") //定义固定的GET,请求路径为"/search.htm"
|
|
|
|
|
//设置请求头
|
|
|
|
|
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //设置请求头:接受的响应类型
|
|
|
|
|
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent,模拟浏览器请求
|
|
|
|
|
"Accept-Charset:UTF-8", //设置字符集为 UTF-8
|
|
|
|
|
"Connection:close", //请求头:请求完成后关闭连接
|
|
|
|
|
"Cache-Control:no-cache"}) //禁用缓存
|
|
|
|
|
//使用@Query注解传递查询参数,表示关键词和页码
|
|
|
|
|
Observable<String> searchBook(@Query("keyword")String content, @Query("pn")int page);
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
|
|
|
|
|
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
|
|
|
|
|
"Accept-Charset:UTF-8",
|
|
|
|
|
"Connection:close",
|
|
|
|
|
"Cache-Control:no-cache"})
|
|
|
|
|
//获取书籍内容的请求
|
|
|
|
|
@GET //定义GET请求
|
|
|
|
|
//设置请求头
|
|
|
|
|
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
|
|
|
|
|
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent,模拟浏览器请求
|
|
|
|
|
"Accept-Charset:UTF-8", //设置字符集为 UTF-8
|
|
|
|
|
"Connection:close", //请求头:请求完成后关闭连接
|
|
|
|
|
"Cache-Control:no-cache"}) //禁用缓存
|
|
|
|
|
//该方法接收动态URL,返回书籍的内容
|
|
|
|
|
Observable<String> getBookContent(@Url String url);
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
|
|
|
|
|
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
|
|
|
|
|
"Accept-Charset:UTF-8",
|
|
|
|
|
"Connection:close",
|
|
|
|
|
"Cache-Control:no-cache"})
|
|
|
|
|
//获取章节列表的请求
|
|
|
|
|
@GET //定义GET请求
|
|
|
|
|
//设置请求头
|
|
|
|
|
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
|
|
|
|
|
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent,模拟浏览器请求
|
|
|
|
|
"Accept-Charset:UTF-8", //设置字符集为 UTF-8
|
|
|
|
|
"Connection:close", //请求头:请求完成后关闭连接
|
|
|
|
|
"Cache-Control:no-cache"}) //禁用缓存
|
|
|
|
|
//该方法接收动态URL,返回章节列表
|
|
|
|
|
Observable<String> getChapterList(@Url String url);
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
|
|
|
|
|
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
|
|
|
|
|
"Accept-Charset:UTF-8",
|
|
|
|
|
"Connection:close",
|
|
|
|
|
"Cache-Control:no-cache"})
|
|
|
|
|
//获取书籍类型相关书籍的请求
|
|
|
|
|
@GET //定义GET请求
|
|
|
|
|
//设置请求头
|
|
|
|
|
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
|
|
|
|
|
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent,模拟浏览器请求
|
|
|
|
|
"Accept-Charset:UTF-8", //设置字符集为 UTF-8
|
|
|
|
|
"Connection:close", //请求头:请求完成后关闭连接
|
|
|
|
|
"Cache-Control:no-cache"}) //禁用缓存
|
|
|
|
|
//该方法接收动态URL,返回该类型的书籍
|
|
|
|
|
Observable<String> getKindBooks(@Url String url);
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
|
|
|
|
|
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
|
|
|
|
|
"Accept-Charset:UTF-8",
|
|
|
|
|
"Connection:close",
|
|
|
|
|
"Cache-Control:no-cache"})
|
|
|
|
|
// 获取图书馆数据的请求
|
|
|
|
|
@GET //定义GET请求
|
|
|
|
|
//设置请求头
|
|
|
|
|
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
|
|
|
|
|
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent,模拟浏览器请求
|
|
|
|
|
"Accept-Charset:UTF-8", //设置字符集为 UTF-8
|
|
|
|
|
"Connection:close", //请求头:请求完成后关闭连接
|
|
|
|
|
"Cache-Control:no-cache"}) //禁用缓存
|
|
|
|
|
//该方法接收动态URL,返回图书馆相关的数据
|
|
|
|
|
Observable<String> getLibraryData(@Url String url);
|
|
|
|
|
}
|
|
|
|
|
|