Libraryless. Click here for Pure Java version (4288L/26K).
1 | static new ThreadLocal<Bool> doPost_silently; |
2 | static new ThreadLocal<Long> doPost_timeout; |
3 | static new ThreadLocal<SS> doPost_extraHeaders; |
4 | |
5 | sS doPost(S url, Map urlParameters) { |
6 | ret doPost(urlParameters, url); |
7 | } |
8 | |
9 | sS doPost(Map urlParameters, S url) { |
10 | ret doPost(makePostData(urlParameters), url); |
11 | } |
12 | |
13 | static String doPost(S urlParameters, String url) ctex { |
14 | URL _url = new URL(url); |
15 | ping(); |
16 | return doPost(urlParameters, _url.openConnection(), _url); |
17 | } |
18 | |
19 | static String doPost(S urlParameters, URLConnection conn, URL url) ctex { |
20 | bool silently = isTrue(optParam(doPost_silently)); |
21 | Long timeout = optParam(doPost_timeout); |
22 | SS extraHeaders = optPar(doPost_extraHeaders); |
23 | setHeaders(conn); |
24 | for (S key : keys(extraHeaders)) { |
25 | ifdef doPost_debug |
26 | print("doPost sending header: " + key + " = " + extraHeaders.get(key)); |
27 | endifdef |
28 | conn.setRequestProperty(key, extraHeaders.get(key)); |
29 | } |
30 | |
31 | int l = lUtf8(urlParameters); |
32 | if (!silently) |
33 | print("Sending POST request: " + hideCredentials(url) + " (" + l + " bytes)"); |
34 | |
35 | // connect and do POST |
36 | if (timeout != null) setURLConnectionTimeouts(conn, timeout); |
37 | ((HttpURLConnection) conn).setRequestMethod("POST"); |
38 | conn.setDoOutput(true); |
39 | conn.setRequestProperty("Content-Length", str(l)); |
40 | |
41 | OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream(), "UTF-8"); |
42 | writer.write(urlParameters); |
43 | writer.flush(); |
44 | |
45 | String contents = loadPage_utf8(conn, url, false); |
46 | writer.close(); |
47 | return contents; |
48 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney
ID | Author/Program | Comment | Date |
---|---|---|---|
752 | #1000604 (pitcher) | 2015-08-18 00:07:22 |
Snippet ID: | #1000565 |
Snippet name: | doPost |
Eternal ID of this version: | #1000565/18 |
Text MD5: | dfcb1444bd3a2b035a9f54616dfcd4a1 |
Transpilation MD5: | 884cf9c48f771a87f011760df15042d7 |
Author: | stefan |
Category: | |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-05-29 16:30:50 |
Source code size: | 1552 bytes / 48 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 1028 / 3805 |
Version history: | 17 change(s) |
Referenced in: | [show references] |