Search in sources :

Example 1 with GetMethod

use of com.shizhefei.mvc.http.okhttp.GetMethod in project MVCHelper by LuckyJayce.

the class BooksOkHttp_SyncDataSource method loadBooks.

private List<Book> loadBooks(final int page) throws Exception {
    GetMethod method = new GetMethod("https://www.baidu.com");
    method.addHeader("a", "aaaaa");
    method.addParam("api_key", "75ee6c644cad38dc8e53d3598c8e6b6c");
    List<Book> data = method.executeSync(new ResponseParser<List<Book>>() {

        @Override
        public List<Book> parse(Response response) throws Exception {
            Thread.sleep(1000);
            List<Book> books = new ArrayList<Book>();
            for (int i = 0; i < 15; i++) {
                books.add(new Book("page" + page + "  Java编程思想 " + i, 108.00d));
            }
            mPage = page;
            return books;
        }
    });
    return data;
}
Also used : Response(okhttp3.Response) Book(com.shizhefei.test.models.enties.Book) GetMethod(com.shizhefei.mvc.http.okhttp.GetMethod) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with GetMethod

use of com.shizhefei.mvc.http.okhttp.GetMethod in project MVCHelper by LuckyJayce.

the class BooksOkHttp_AsyncDataSource method loadBooks.

private RequestHandle loadBooks(final ResponseSender<List<Book>> sender, final int page) throws Exception {
    GetMethod method = new GetMethod("https://www.baidu.com");
    method.addHeader("a", "aaaaa");
    method.addParam("api_key", "75ee6c644cad38dc8e53d3598c8e6b6c");
    method.executeAsync(sender, new ResponseParser<List<Book>>() {

        @Override
        public List<Book> parse(Response response) throws Exception {
            Thread.sleep(1000);
            List<Book> books = new ArrayList<Book>();
            for (int i = 0; i < 15; i++) {
                books.add(new Book("page" + page + "  Java编程思想 " + i, 108.00d));
            }
            mPage = page;
            return books;
        }
    });
    //        });
    return method;
}
Also used : Response(okhttp3.Response) Book(com.shizhefei.test.models.enties.Book) GetMethod(com.shizhefei.mvc.http.okhttp.GetMethod) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with GetMethod

use of com.shizhefei.mvc.http.okhttp.GetMethod in project MVCHelper by LuckyJayce.

the class GankMeizhiOkHttp_Datasource method load.

private RequestHandle load(ResponseSender<List<Meizhi>> sender, final int page) {
    // http://gank.io/api/data/Android/10/1
    String url = new UrlBuilder("http://gank.io/api/data").sp("福利").sp("10").sp(page).build();
    GetMethod method = new GetMethod(url);
    method.executeAsync(sender, new MeizhiParser<List<Meizhi>>() {

        @Override
        protected void onParse(Response responses, List<Meizhi> meizhis) {
            mPage = page;
        }
    });
    return method;
}
Also used : Response(okhttp3.Response) GetMethod(com.shizhefei.mvc.http.okhttp.GetMethod) List(java.util.List) UrlBuilder(com.shizhefei.mvc.http.UrlBuilder) Meizhi(com.shizhefei.test.models.enties.Meizhi)

Aggregations

GetMethod (com.shizhefei.mvc.http.okhttp.GetMethod)3 List (java.util.List)3 Response (okhttp3.Response)3 Book (com.shizhefei.test.models.enties.Book)2 ArrayList (java.util.ArrayList)2 UrlBuilder (com.shizhefei.mvc.http.UrlBuilder)1 Meizhi (com.shizhefei.test.models.enties.Meizhi)1