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

50
LINES

< > BotCompany Repo | #1000565 // doPost

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

Transpiled version (4288L) is out of date.

static new ThreadLocal<Bool> doPost_silently;
static new ThreadLocal<Long> doPost_timeout;
static new ThreadLocal<SS> doPost_extraHeaders;

sS doPost(S url, Map urlParameters) {
  ret doPost(urlParameters, url);
}

sS doPost(Map urlParameters, S url) {
  ret doPost(makePostData(urlParameters), url);
}

static String doPost(S urlParameters, String url) ctex {
  URL _url = new URL(url);
  ping();
  return doPost(urlParameters, _url.openConnection(), _url);
}

static String doPost(S urlParameters, URLConnection conn, URL url) ctex {
  bool silently = isTrue(optParam(doPost_silently));
  Long timeout = optParam(doPost_timeout);
  SS extraHeaders = optPar(doPost_extraHeaders);
  setHeaders(conn);
  for (S key : keys(extraHeaders)) {
    ifdef doPost_debug
      print("doPost sending header: " + key + " = " + extraHeaders.get(key));
    endifdef
    conn.setRequestProperty(key, extraHeaders.get(key));
  }

  int l = lUtf8(urlParameters);
  if (!silently)
    print("Sending POST request: " + hideCredentials(url) + " (" + l + " bytes)");
      
  // connect and do POST
  if (timeout != null) setURLConnectionTimeouts(conn, timeout);
  cast conn to HttpURLConnection;
  conn.setRequestMethod("POST");
  conn.setDoOutput(true);
  conn.setFixedLengthStreamingMode(l);
  //conn.setRequestProperty("Content-Length", str(l));

  OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
  writer.write(urlParameters);
  writer.flush();

  String contents = loadPage_utf8(conn, url, false);
  writer.close();
  return contents;
}

download  show line numbers  debug dex  old transpilations   

Relations

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gjtlkbvenryc, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney

118 comment(s) hidden. show

Snippet ID: #1000565
Snippet name: doPost
Eternal ID of this version: #1000565/20
Text MD5: 6bee11333ec1f3160e8728404bb46d30
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2024-03-29 11:01:17
Source code size: 1607 bytes / 50 lines
Pitched / IR pitched: No / No
Views / Downloads: 1234 / 4095
Version history: 19 change(s)
Referenced in: [show references]