Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

27
LINES

< > BotCompany Repo | #1030464 // PostRequest

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4392L/27K).

1  
sclass PostRequest {
2  
  S method = "POST";
3  
  S url;
4  
  MapSO params = new LinkedHashMap;
5  
  SS headers = new LinkedHashMap;
6  
  
7  
  *() {}
8  
  *(S *url, O... _) { params = paramsToMap(_); }
9  
  
10  
  S perform() {
11  
    if (eq(method, "POST"))
12  
      ret doPostWithHeaders(url, headers, params);
13  
    else if (eq(method, "GET"))
14  
      ret loadPageWithHeaders(appendQueryToURL(url, params), headers);
15  
    else fail("Unknown method: " + method);
16  
  }
17  
  
18  
  selfType set(S param, O value) {
19  
    params.put(param, value);
20  
    this;
21  
  }
22  
  
23  
  selfType switchToGet() {
24  
    method = "GET";
25  
    this;
26  
  }
27  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030464
Snippet name: PostRequest
Eternal ID of this version: #1030464/10
Text MD5: 3437b7b94b114ff5c90869e578a684ee
Transpilation MD5: 10398d172f647884f014f8ddd1c44d16
Author: stefan
Category: javax / networking
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-12-22 23:29:25
Source code size: 604 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 249 / 518
Version history: 9 change(s)
Referenced in: [show references]