List of utility methods to do HTTP Post
String | post(String url, String body, Map Send a post request return fetch("POST", url, body, headers); |
String | post(String url, String payload) post URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("User-Agent", USER_AGENT); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(payload); ... |
HttpURLConnection | post(String url, String postdata, String cookie) post HttpURLConnection pHuc = getConnection(url); pHuc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); pHuc.setRequestProperty("Origin", url.substring(0, url.indexOf("/"))); pHuc.setRequestProperty("Host", url.substring(0, url.indexOf("/"))); pHuc.setRequestProperty("Cookie", cookie); try { pHuc.setRequestMethod("POST"); pHuc.setDoOutput(true); ... |
HttpURLConnection | Post(URL url, Map fields) Post String body;
body = encodeToForm(fields);
return Post(url, body);
|
String | post(URL url, Map POST to the specified URL with the specified map of values. return post(url, implode(values));
|
String | post(URL url, String content) post return post(url, content, "application/x-www-form-urlencoded"); |
InputStream | post(URL url, String contentType, byte[] data) Sends HTTP POST request HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setDoOutput(true); con.setRequestMethod("POST"); con.setRequestProperty("content-Type", contentType); OutputStream out = con.getOutputStream(); try { out.write(data, 0, data.length); out.flush(); ... |
JsonObject | postCall(JsonObject json, String url) post Call try { HttpURLConnection connection = getConnection(url); try (OutputStreamWriter osw = new OutputStreamWriter(connection.getOutputStream())) { osw.write(json.toString()); osw.flush(); int responseCode = connection.getResponseCode(); if (responseCode != 200) { ... |
void | postData(Reader data, URL endpoint, Writer output) Reads data from the data reader and posts it to a server via a POST request. HttpURLConnection urlc = null; try { urlc = (HttpURLConnection) endpoint.openConnection(); try { urlc.setRequestMethod("POST"); } catch (ProtocolException e) { throw new RuntimeException("Shouldn't happen: HttpURLConnection doesn't support POST??", e); urlc.setDoOutput(true); urlc.setDoInput(true); urlc.setUseCaches(false); urlc.setAllowUserInteraction(false); urlc.setRequestProperty("Content-type", "text/xml; charset=" + "UTF-8"); OutputStream out = urlc.getOutputStream(); try { Writer writer = new OutputStreamWriter(out, "UTF-8"); pipe(data, writer); writer.close(); } finally { if (out != null) { try { out.close(); } catch (Exception e) { InputStream in = urlc.getInputStream(); try { Reader reader = new InputStreamReader(in); pipe(reader, output); reader.close(); } finally { if (in != null) in.close(); } finally { if (urlc != null) urlc.disconnect(); |
String | postForm(String url, Map Post a form with parameters return postForm(url, params, null);
|