/** * No-arg constructor. * * @since 2.0 */ public EntityEnclosingMethod() { super(); setFollowRedirects(false); }
/** * No-arg constructor. * * @since 1.0 */ public GetMethod() { setFollowRedirects(true); }
GetMethod get = new GetMethod("http://httpcomponents.apache.org"); // execute method and handle any error responses. ... InputStream in = get.getResponseBodyAsStream(); // Process the data from the input stream. get.releaseConnection();
GetMethod getMethod = new GetMethod("http://www.example.com"); int res = client.executeMethod(getMethod);
StringRequestEntity requestEntity = new StringRequestEntity( JSON_STRING, "application/json", "UTF-8"); PostMethod postMethod = new PostMethod("http://example.com/action"); postMethod.setRequestEntity(requestEntity); int statusCode = httpClient.executeMethod(postMethod);
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.
/** * No-arg constructor. * * @since 1.0 */ public HeadMethod() { setFollowRedirects(true); }
/** * @param requestEntity The requestEntity to set. * * @since 3.0 */ public void setRequestEntity(RequestEntity requestEntity) { clearRequestBody(); this.requestEntity = requestEntity; }
/** * @return Returns the requestEntity. * * @since 3.0 */ public RequestEntity getRequestEntity() { return generateRequestEntity(); }
/** * Get a list of allowed methods. * @return An enumeration of all the allowed methods. * * @since 1.0 */ public Enumeration getAllowedMethods() { checkUsed(); return methodsAllowed.elements(); }
/** * Gets the content length. If the content length has not been set, the content will be * buffered to determine the actual content length. */ public long getContentLength() { if (contentLength == CONTENT_LENGTH_AUTO && buffer == null) { bufferContent(); } return contentLength; }
/** * Constructor specifying a URI. * * @param uri either an absolute or relative URI * * @since 2.0 * */ public TraceMethod(String uri) { super(uri); setFollowRedirects(false); }
/** * Entity enclosing requests cannot be redirected without user intervention * according to RFC 2616. * * @param followRedirects must always be <code>false</code> */ public void setFollowRedirects(boolean followRedirects) { if (followRedirects == true) { throw new IllegalArgumentException("Entity enclosing requests cannot be redirected without user intervention"); } super.setFollowRedirects(false); }
String response; String url = "www.blah.com/path?key=value"; GetMethod method = new GetMethod(url); int status = client.executeMethod(method);
/** * Constructor specifying a URI. * * @param uri either an absolute or relative URI * * @since 1.0 */ public GetMethod(String uri) { super(uri); LOG.trace("enter GetMethod(String)"); setFollowRedirects(true); }
/** * Constructor specifying a URI. * * @param uri either an absolute or relative URI * * @since 1.0 */ public HeadMethod(String uri) { super(uri); setFollowRedirects(true); }
/** * Constructor specifying a URI. * * @param uri either an absolute or relative URI * * @since 2.0 */ public EntityEnclosingMethod(String uri) { super(uri); setFollowRedirects(false); }
/** * Sets the request body to be the specified inputstream. * * @param body Request body content as {@link java.io.InputStream} * * @deprecated use {@link #setRequestEntity(RequestEntity)} */ public void setRequestBody(InputStream body) { LOG.trace("enter EntityEnclosingMethod.setRequestBody(InputStream)"); clearRequestBody(); this.requestStream = body; }
/** * Is the specified method allowed ? * * @param method The method to check. * @return true if the specified method is allowed. * @since 1.0 */ public boolean isAllowed(String method) { checkUsed(); return methodsAllowed.contains(method); }
String url = "http://www.example.com/page?key=value"; GetMethod method = new GetMethod(url);