Open source is really a good thing. We don't need to recreate the wheel. Many stubborn people always look down on people who use the framework and think that there is no technical content and they should write everything on their own. In fact, the first task in our work is to complete the work, and to complete the work better. These open-source frameworks have been verified and corrected by many people. It is better than writing it by yourself. Don't repeat the wheel. Besides, for users, it is to see whose products are doing well, rather than who has better developer technology.
This AsynchHttpClient has many advantages. In particular, it is very simple to write, so you do not need to access the network to open sub-threads, and modify the interface information to create another handler. As for how to use it, first download the jar package, or download the source code to your src file. Search android from github and you will be able to find it. This is very popular.
Code:
Public void postFile () throws Exception {String path = ""; File file = new File (path); if (file. exists () & file. length ()> 0) {AsyncHttpClient client = new AsyncHttpClient (); RequestParams params = new RequestParams (); params. put ("profile_picture", file); client. post ("http: // 192.168.1.100: 8080/web/UploadFile", params, new AsyncHttpResponseHandler () {@ Overridepublic void onSuccess (int statusCode, Header [] headers, byte [] responseBody) {Toast. makeText (MainActivity. this, "success", Toast. LENGTH_LONG ). show () ;}@ Overridepublic void onFailure (int statusCode, Header [] headers, byte [] responseBody, Throwable error) {Toast. makeText (MainActivity. this, "failed", Toast. LENGTH_LONG ). show () ;}}) ;}else {Toast. makeText (this, "the file does not exist", 1 ). show ();}}