Register request body
@ReqTags("Registered")
public class RegisterReq extends CommonRequest {
    public String username;
    public String password;
    public String repassword;

    public RegisterReq(String username, String password, String repassword) {
        this.username = username;
        this.password = password;
        this.repassword = repassword;
    }

    public RegisterReq() {
    }

    @Override
    public String postfix() {
        return "user/register"; }}Copy the code
The initiating
final RegisterReq json = new RegisterReq("12132322333"."123456"."123456");
 HttpRequestFactory.doPost(json, new ResultCallbackAdapt<HttpCommObjResp<RegisterResp>>() {
            @Override
            public void doOnResponse(HttpCommObjResp<RegisterResp> response) {
                System.out.println(response + "");
                mContent.setText("\n mode a return :" + response);
            }

            @Override
            public void doOnError(ApiException ex) {
                System.out.println(ex + "");
                mContent.setText("\n mode a return :"+ ex); } }, iLoading); / / way two HttpRequestFactory. DoPost (json, new ResultCallbackAdapt < String > () {@ Override public voiddoOnResponse(String response) {
                System.out.println(response + "");
                mContent.setText("\n Mode two returns :" + response);
            }

            @Override
            public void doOnError(ApiException ex) {
                System.out.println(ex + "");
                mContent.setText("\n Mode two returns :"+ ex); }});Copy the code

Initialization function

public class MyApplication extends Application
{	
	@Override
    public void onCreate()
    {
        super.onCreate();
         HttpRequestFactory.doCreateHttpReqManager(this, ResLibConfig.DEBUG ? "http://www.wanandroid.com/" : "http://www.wanandroid.com/")
                 .registerCallbacks(new HttpHeadersImpl() {
                     @Override
                     public Map<String, String> generateHeaders() {
                         Map<String, String> keys = new HashMap<>();
                         //        keys.put("versionCode"."" + IUtil.obtainAppVersionCode(ResLibConfig.CONTEXT));
                         //        keys.put("version", IUtil.obtainAppVersion(ResLibConfig.CONTEXT));
                         //        keys.put("channel"."");
                         //        keys.put("imei"."");
                         //        keys.put("platform"."2"); //1:ios 2:Android // keys.put("model", IUtil.MODEL);
                         //        keys.put("vendor", IUtil.BRAND);
                         returnkeys; // Request header injection, if required}}).registerCallbacks(newHttpInterceptor() {
             @Override
             public void doInterceptor(int... cmds) {
                 if(cmds ! = null && cmds.length > 0) { int code = cmds[0]; switch (code) {case HttpInterceptor.KICKED_OFF_LINE:
                             //Tools.showToast("User logged in on another device");
                             int value = AUTO_INCREMENT.incrementAndGet();
                             if(value == 1) { // relogin(); // call once} logger.e ("http"."User login in other equipment has been |" + value + "|");
                             break;
                         case HttpInterceptor.PROHIBIT_USED:
                             //Tools.showToast("You are prohibited from using it.");
                             break;
                         case HttpInterceptor.PROHIBIT_USEDII:
                             //Tools.showToast("User is blocked and cannot log in.");
                             break;
                         case HttpInterceptor.UN_LOGIN:
                             //Tools.showToast("Please log in first.");
                             //relogin(false);
                             break;
                     }
                 }
             }
         }).asEncryptFuncs(new EncryptFuncs() {
             @Override
             public String encrypt(String plainText) {
                 //return AesEncryptionUtil.encrypt(plainText);
                 return "";
             }

             @Override
             public String decrypt(String cipherText) {
                 //return AesEncryptionUtil.decrypt(cipherText);
                 return ""; } / {@ * * * link ReqTags} * {@ link kaiqi. Cn. HTTPX. The req. RegisterReq} * please give the tag, otherwise cancel out request, not intercept encryption to decrypt the ~ * / @ Override public boolean accept(String httpReaTag) {if ("Registered".equals(httpReaTag)) {
                     // return false; // You all agree, I register the first do not agree}return true; // Agree encryption}}).asSubmmitForm(true); // true= Form submissionfalse= json submit}}Copy the code
Tips: Use HttpCommObjResp or HttpCommObjsResp
Form as format:
{
 "code": 200,"msg":"Success"."data":{}
}
Copy the code
Data = {} is an object, so use HttpCommObjResp
Form as format:
{
 "code": 200,"msg":"Success"."data":[]
}
Copy the code
Data = [] is an array object, so use HttpCommObjsResp
I thought all interface returns looked like this, but they don’t
The following is the registration return JSON
{
	"data": {
		"collectIds": []."email": ""."icon": ""."id": 9073,
		"password": "123456"."token": ""."type": 0."username": "19910222"
	},
	"errorCode": 0."errorMsg": ""
}
Copy the code
Why not code, MSG?
Seamless link network call, but don’t be afraid, so provide json, form two submission | download, upload this didn’t bothered to write!!!!!!
Because temporarily support the combination of several return formats, do not meet the format, if necessary, please modify the source code
{
    "msg":""."code"In 100,"data":{}
}
{
    "errorMsg":""."errorCode"In 100,"data":{}
}
{
    "message":""."error"In 100,"infos": {}} {..."results":{}
}
Copy the code
About Cancellation Request
HttpRequestFactory.cancel("Registered"); / / cancel a single HttpRequestFactory. Cancel ("Registered"."Home Page Articles List"); // Cancel multipleCopy the code
About encryption and decryption, only support JSON encryption and decryption temporarily!!
About uploading, the company’s project pictures are now through Ali cloud, there is really no test interface, welcome you to provide test interface, let me improve this library ~
The code still has many inadequacies, please advise

Confuse configuration

When the log is flying everywhere, you say I have a format log tool class, the United States is the United States, many interfaces, it is hard to find ah,
So how can I find the interface information I want?
Good question, look at the log screenshot, a picture is worth a thousand words ~ is not very refreshing, see what I see, love what I love.

Why do you write that? Take a look at the server proxy

	@RequestMapping(value = "/showUser", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json; charset=UTF-8")
	public JSONObject toIndex(@RequestBody(required = false) String data) {
		return callHttpReqTask(data, TO_INDEX);
	}

	@RequestMapping(value = "/addUser", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json; charset=UTF-8")
	public JSONObject addUser(@RequestBody(required = false) String data) {
		return callHttpReqTask(data, ADD_USER);
	}
Copy the code
Each request has a RequestMapping
I construct a suffix on each request body, and the background is interesting.
Call stack is not deep, suitable for beginners to read the source code, there are desirable, give me a star
Reprint with indication of sourceHttpX
In case of needEncryption and decryption library

Mode of use, if required

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io'}}}Copy the code
	dependencies {
    	        implementation 'com. Making. Majunm: HttpX: v1.0.0 - gammax'
    	}
Copy the code