PostMethod post = new PostMethod("http://jakarata.apache.org/"); NameValuePair[] data = { new NameValuePair("user", "joe"), new NameValuePair("password", "bloggs") }; post.setRequestBody(data); // execute method and handle any error responses. ... InputStream in = post.getResponseBodyAsStream(); // handle response.
/** * Uses the post method to send a url with arguments by http, this method can call RESTful Api. * * @param url the http url * @param timeout milliseconds to wait for the server to respond before giving up * @param processInputStream the response body stream processor */ public static void post(String url, Integer timeout, IProcessInputStream processInputStream) throws IOException { Preconditions.checkNotNull(timeout, "timeout"); Preconditions.checkNotNull(processInputStream, "processInputStream"); PostMethod postMethod = new PostMethod(url); try { HttpClient httpClient = new HttpClient(); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(timeout); httpClient.getHttpConnectionManager().getParams().setSoTimeout(timeout); int statusCode = httpClient.executeMethod(postMethod); if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) { InputStream inputStream = postMethod.getResponseBodyAsStream(); processInputStream.process(inputStream); } else { throw new IOException("Failed to perform POST request. Status code: " + statusCode); } } finally { postMethod.releaseConnection(); } }
in = method.getResponseBodyAsStream();
public InputStream getIncomingStream() { try { return postMethod.getResponseBodyAsStream(); } catch (IOException ioe) { return null; } }
private JSONObject parseResult(PostMethod method) throws IOException, JSONException { ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(method.getResponseBodyAsStream(), out); return new JSONObject(new String(out.toByteArray(), "UTF-8")); }
private String readResponse(PostMethod post) throws IOException { InputStream is = post.getResponseBodyAsStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; StringBuilder response = new StringBuilder(); while ((line = rd.readLine()) != null) { response.append(line); response.append('\r'); } rd.close(); return response.toString(); }
public InputStream postInputStream(Object resourceUri, Object restObject, Map<String, Object[]> queryParams, Object... elements) throws Exception { return executePost(resourceUri, restObject, queryParams, elements).getResponseBodyAsStream(); }
PostMethod post = new PostMethod(url); NameValuePair[] data = { new NameValuePair("username", user), new NameValuePair("password", password) }; post.setRequestBody(data); HttpClient client = new DefaultHttpClient(); client.execute(post); InputStream in = post.getResponseBodyAsStream(); // handle response...
try { String postURL= server; HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod(postURL);; client.executeMethod(postMethod); InputStream input = postMethod.getResponseBodyAsStream(); //--your subsequent code here
PostMethod post = new PostMethod( "http://api.grooveshark.com/ws3.php?sig=f699614eba23b4b528cb830305a9fc77" ); NameValuePair[] data = { new NameValuePair( "method", "addUserFavoriteSong..." ), ... }; post.setRequestBody(data); InputStream in = post.getResponseBodyAsStream(); ...
PostMethod post = new PostMethod("http://jakarata.apache.org/"); NameValuePair[] data = { new NameValuePair("user", "joe"), new NameValuePair("password", "bloggs") }; post.setRequestBody(data); // execute method and handle any error responses. ... InputStream in = post.getResponseBodyAsStream(); // handle response.
PostMethod post = new PostMethod("http://jakarata.apache.org/"); NameValuePair[] data = { new NameValuePair("user", "joe"), new NameValuePair("password", "bloggs") }; post.setRequestBody(data); // execute method and handle any error responses. ... InputStream in = post.getResponseBodyAsStream(); // handle response.
PostMethod post = new PostMethod("http://jakarata.apache.org/"); NameValuePair[] data = { new NameValuePair("user", "joe"), new NameValuePair("password", "bloggs") }; post.setRequestBody(data); // execute method and handle any error responses. ... InputStream in = post.getResponseBodyAsStream(); // handle response.
PostMethod post = new PostMethod("https://www.walmart.com/subflow/YourAccountLoginContext/1471476370/sub_generic_login/create_account.do"); NameValuePair[] data = { new NameValuePair("firstName", "joe"), new NameValuePair("lastName", "bloggs") }; post.setRequestBody(data); InputStream in = post.getResponseBodyAsStream(); // handle response.
HttpClient client = new HttpClient(); PostMethod post = new PostMethod("http://jakarata.apache.org/"); NameValuePair[] data = { new NameValuePair("user", "joe"), new NameValuePair("password", "bloggs") }; post.setRequestBody(data); int returnCode = client.execute(post); // check return code ... InputStream in = post.getResponseBodyAsStream();
protected InputStream getInputStream() throws XmlRpcException { try { checkStatus(method); return method.getResponseBodyAsStream(); } catch (HttpException e) { throw new XmlRpcClientException("Error in HTTP transport: " + e.getMessage(), e); } catch (IOException e) { throw new XmlRpcClientException("I/O error in server communication: " + e.getMessage(), e); } }
PostMethod post = new PostMethod("http://jakarata.apache.org/"); NameValuePair[] data = { new NameValuePair("user", "joe"), new NameValuePair("password", "bloggs") }; post.setRequestBody(data); post.setRequestHeader("Content-type", "application/xhtml+xml"); // execute method and handle any error responses. ... InputStream in = post.getResponseBodyAsStream(); // handle response.
PostMethod post = new PostMethod("https URL of form action goes here"); NameValuePair[] data = { new NameValuePair("first_name", "joe"), new NameValuePair("last_name", "Doe") }; post.setRequestBody(data); post.addRequestHeader("Referer", "URL of referring web page goes here"); // TODO: execute method and handle any error responses. ... InputStream inPage = post.getResponseBodyAsStream(); // handle response.
protected InputStream getInputStream() throws XmlRpcException { try { checkStatus(method); return method.getResponseBodyAsStream(); } catch (HttpException e) { throw new XmlRpcClientException("Error in HTTP transport: " + e.getMessage(), e); } catch (IOException e) { throw new XmlRpcClientException("I/O error in server communication: " + e.getMessage(), e); } }
PostMethod post = new PostMethod("http://localhost:8118/log.srv"); post.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded"); NameValuePair[] data = { new NameValuePair("action", "likearticle"), new NameValuePair("noname", "989858"), new NameValuePair("ladoi", "cutymaraton") }; post.setRequestBody(data); HttpClient httpclient = new HttpClient(); int result = httpclient.executeMethod(post); InputStream in = post.getResponseBodyAsStream(); // handle response.