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).

sclass PostRequest {
  S method = "POST";
  S url;
  MapSO params = new LinkedHashMap;
  SS headers = new LinkedHashMap;
  
  *() {}
  *(S *url, O... _) { params = paramsToMap(_); }
  
  S perform() {
    if (eq(method, "POST"))
      ret doPostWithHeaders(url, headers, params);
    else if (eq(method, "GET"))
      ret loadPageWithHeaders(appendQueryToURL(url, params), headers);
    else fail("Unknown method: " + method);
  }
  
  selfType set(S param, O value) {
    params.put(param, value);
    this;
  }
  
  selfType switchToGet() {
    method = "GET";
    this;
  }
}

download  show line numbers  debug dex   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

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: 43 / 111
Version history: 9 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1030464 & http://1030464.tinybrain.de