Giter Club home page Giter Club logo

fasthttpclient's Introduction

FastHttpClient

封装OkHttp(jdk8以上)

====== powered by icecooly([email protected]).

Usage

1.synchronized get

FastHttpClient.get().
		url(url).
		addParams("userName", "icecool").
		addParams("password", "111111").
		build().
		execute();

2.synchronized post

FastHttpClient.post().
		url(url).
		addParams("userName", "icecool").
		addParams("password", "111111").
		build().
		execute();

3.asynchronized get

FastHttpClient.get().
			url(url).
			addParams("userName","icecool").
			addParams("password", "111111").
			build().
			executeAsync(new Callback() {
			@Override
			public void onFailure(Call call, Exception e, int id) {
				//TODO
			}

			@Override
			public void onResponse(Call call,Response response, int id) {
				try {
					System.out.println(response.body().string());
				} catch (IOException e) {
				}
			}
		});

4.asynchronized post

FastHttpClient.post().
			url(url).
			addParams("userName","icecool").
			addParams("password", "111111").
			build().
			executeAsync(new Callback() {
			@Override
			public void onFailure(Call call, Exception e, int id) {
				//TODO
			}

			@Override
			public void onResponse(Call call,Response response, int id) {
				try {
					System.out.println(response.body().string());
				} catch (IOException e) {
				}
			}
		});

5.download file aynsc

FastHttpClient.get().
		url("http://e.hiphotos.baidu.com/image/pic/item/faedab64034f78f0b31a05a671310a55b3191c55.jpg").
		build().addNetworkInterceptor(new DownloadFileInterceptor(){
			@Override
			public void updateProgress(long downloadLenth, long totalLength, boolean isFinish) {
				System.out.println("updateProgress downloadLenth:"+downloadLenth+
						",totalLength:"+totalLength+",isFinish:"+isFinish);
			}
		}).
		executeAsync(new DownloadFileCallback("/tmp/tmp.jpg") {//save file to /tmp/tmp.jpg
				@Override
				public void onFailure(Call call, Exception e, int id) {
					e.printStackTrace();
				}
				@Override
				public void onSuccess(Call call, File file, int id) {
					super.onSuccess(call, file, id);
					System.out.println("filePath:"+file.getAbsolutePath());
				}
				@Override
				public void onSuccess(Call call, InputStream fileStream, int id) {
					System.out.println("onSuccessWithInputStream");
				}
		});
Thread.sleep(50000);

6.upload file

byte[] imageContent=FileUtil.getBytes("/tmp/test.png");
		response = FastHttpClient.post().
				url(url).
				addFile("file1", "a.txt", "123").
				addFile("file2", "b.jpg", imageContent).
				build().
				connTimeOut(10000).
				execute();
System.out.println(response.body().string());

7.https get

Response response = FastHttpClient.get().url("https://kyfw.12306.cn/otn/").
				build()
				.execute();
System.out.println(response.body().string());

8.https post

Response response = FastHttpClient.post().url("https://kyfw.12306.cn/otn/").
				build()
				.execute();
System.out.println(response.body().string());

9.make jar Eclipse->Window->Show View->Ant build.xml taget ->make jar make all jars into one jar(default release/fasthttpclient-1.0.jar)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.