Okhttp packaging and use of a detailed

Source: Internet
Author: User

GitHub Address

' cn.yuan.yu:library:1.0.2 '

First step: Initialize our tool class

 Public classMyApplication extends Application {Private StaticHandler MainHandler; Private StaticContext instance; @Override Public voidonCreate () {super.oncreate (); Instance= This; MainHandler=NewHandler (); /** Initialize Okhttputils * The first parameter is whether to submit the form of JSON data or form * The second parameter is the identity of the request returned code * The third parameter is the correct co to be returned by the request The de value * The fourth parameter is the prompt message returned by the request key * The fifth parameter is to synchronize the thread's problem * The sixth parameter is the context that pops up the hint message*/okhttputilsconfig.getinstance (). Init (false,"ResultCode"," -","msg", MainHandler, This); }}
 Public classMyApplication extends Application {Private StaticHandler MainHandler; Private StaticContext instance; @Override Public voidonCreate () {super.oncreate (); Instance= This; MainHandler=NewHandler (); /** Initialize Okhttputils * The first parameter is whether to submit the form of JSON data or form * The second parameter is the identity of the request returned code * The third parameter is the correct co to be returned by the request The de value * The fourth parameter is the prompt message returned by the request key * The fifth parameter is to synchronize the thread's problem * The sixth parameter is the context that pops up the hint message*/okhttputilsconfig.getinstance (). Init (false,"ResultCode"," -","msg", MainHandler, This); }}

The second step, the direct call to use, is so simple rough

Jsonobject Jsonobject =NewJsonobject (); Jsonobject.put ("username", username); Jsonobject.put ("Password", PWD); L.D ("Login", jsonobject.tojsonstring ()); Requestpacket Requestpacket=NewRequestpacket (); Requestpacket.url=Constanturl.getbaseurl (); Requestpacket.addargument ("Data", jsonobject.tojsonstring ()); Requestpacket.addargument ("Query","Login"); Okhttputil.request (Requestpacket.post,requestpacket,NewResponselistener<registgetvcodebean>() {@Override Public voidonsuccess (Registgetvcodebean registgetvcodebean) {//Todo somethiing} @Override Public voidonfailure (String responseresult) {//Todo somethiing                    }                });

Registgetvcodebean

 Public class Registgetvcodebean {}

The source of this article: 62897368

Okhttp packaging and use of a detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.