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);
Part[] parts = {new StringPart(schema.getSchemaName(), schema.toString())}; MultipartRequestEntity requestEntity = new MultipartRequestEntity(parts, new HttpMethodParams()); httpPost.setRequestEntity(requestEntity); int responseCode = HTTP_CLIENT.executeMethod(httpPost); if (responseCode >= 400) {
public static PostMethod sendMultipartPostRequest(String url, String body) throws IOException { HttpClient httpClient = new HttpClient(); PostMethod postMethod = new PostMethod(url); // our handlers ignore key...so we can put anything here Part[] parts = {new StringPart("body", body)}; postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams())); httpClient.executeMethod(postMethod); return postMethod; }
PostMethod post = new PostMethod(url); RequestEntity entity = new FileRequestEntity(inputFile, "text/xml; charset=ISO-8859-1"); post.setRequestEntity(entity); HttpClient httpclient = new HttpClient(); int result = httpclient.executeMethod(post);
@Override public HTTPResponse post( final URL url, final InputStream postContent, final String postContentType) throws IOException { PostMethod postMethod = new PostMethod(url.toExternalForm()); postMethod.setDoAuthentication(user != null && password != null); if (postContentType != null) { postMethod.setRequestHeader("Content-type", postContentType); } RequestEntity requestEntity = new InputStreamRequestEntity(postContent); postMethod.setRequestEntity(requestEntity); int responseCode = client.executeMethod(postMethod); if (200 != responseCode) { postMethod.releaseConnection(); throw new IOException( "Server returned HTTP error code " + responseCode + " for URL " + url.toExternalForm()); } return new HttpMethodResponse(postMethod); }
@Override public HTTPResponse post( final URL url, final InputStream postContent, final String postContentType) throws IOException { PostMethod postMethod = new PostMethod(url.toExternalForm()); postMethod.setDoAuthentication(user != null && password != null); if (tryGzip) { postMethod.setRequestHeader("Accept-Encoding", "gzip"); } if (postContentType != null) { postMethod.setRequestHeader("Content-type", postContentType); } RequestEntity requestEntity = new InputStreamRequestEntity(postContent); postMethod.setRequestEntity(requestEntity); int responseCode = executeMethod(postMethod); if (200 != responseCode) { postMethod.releaseConnection(); throw new IOException( "Server returned HTTP error code " + responseCode + " for URL " + url.toExternalForm()); } return new HttpMethodResponse(postMethod); }
post.setRequestEntity(requestEntity);
@Override public void connect() throws ConnectionException { PostMethod post = new PostMethod(conn.getConnectUrl()); HttpClient httpClient = new HttpClient(); if (conn.getConnectUrl().toLowerCase().startsWith("https://")) { registerSsl(); } addPostHeaders(post); try { StringRequestEntity requestEntity = new StringRequestEntity("{}", "application/json", "UTF-8"); post.setRequestEntity(requestEntity); httpClient.executeMethod(post); if (post.getStatusCode() != 200 && post.getStatusCode() != 201) { logger.error("Connect failed with error code " + post.getStatusCode() + " and message:\n" + post.getResponseBodyAsString()); throw new ConnectionException("Connect failed, error code " + post.getStatusCode() + " and message: " + post.getResponseBodyAsString()); } } catch (HttpException e) { logger.error(e.getLocalizedMessage(), e); throw new ConnectionException(e.getLocalizedMessage()); } catch (IOException e) { logger.error(e.getLocalizedMessage(), e); throw new ConnectionException(e.getLocalizedMessage()); } }
@Override public void prepareRequest() throws Exception { PostMethod method = new PostMethod(URL); method.setRequestHeader(HEADER_NAME, HEADER_VALUE); RequestEntity body = new StringRequestEntity(PAYLOAD,CONTENT_TYPE,null); method.setRequestEntity(body); request = new Http3RequestAdapter(method); } }
public String call(String xml) { PostMethod post = new PostMethod(url); post.setRequestEntity(new StringRequestEntity(xml)); post.setRequestHeader("Content-type", "text/xml");
protected <T> String executeCreateObject(final T newObject, final String uri, final Map<String, String> parameters) throws BigSwitchBcfApiException { checkInvariants(); PostMethod pm = (PostMethod)createMethod("post", uri, _port); setHttpHeader(pm); try { pm.setRequestEntity(new StringRequestEntity(gson.toJson(newObject), CONTENT_JSON, null)); } catch (UnsupportedEncodingException e) { throw new BigSwitchBcfApiException("Failed to encode json request body", e); } executeMethod(pm); String hash = checkResponse(pm, "BigSwitch HTTP create failed: "); pm.releaseConnection(); return hash; }
post.setRequestEntity(entity); if (httpClient.executeMethod(post) != 200) { return new SecurityGroupRuleAnswer(cmd, false,
postMethod.setRequestEntity(entity);
public OutputStream getOutgoingStream() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); RequestEntity requestEntity = new OutputStreamRequestEntity(outputStream); postMethod.setRequestEntity(requestEntity); return outputStream; }
String xml = "whatever.your.xml.is.here"; PostMethod post = new PostMethod(strURL); try { StringRequestEntity requestEntity = new StringRequestEntity(xml); post.setRequestEntity(requestEntity); ....
[...] PostMethod post = new PostMethod(url); post.setRequestEntity(new ByteArrayEntity(bytes)); post.setRequestHeader("Content-type", "application/octet-stream"); [...]
String xml = "your xml"; PostMethod post = new PostMethod(strURL); try { StringRequestEntity requestEntity = new StringRequestEntity(xml); post.setRequestEntity(requestEntity); .. .... ...
@Override public String postJson(String url, String body) throws RobotConnectionException { PostMethod method = new PostMethod(url); try { method.setRequestEntity(new StringRequestEntity(body, RobotConnection.JSON_CONTENT_TYPE, Charsets.UTF_8.name())); return fetch(url, method); } catch (IOException e) { String msg = "Robot fetch http failure: " + url + ": " + e; throw new RobotConnectionException(msg, e); } }
File f = new File("/path/fileToUpload.txt"); PostMethod filePost = new PostMethod("http://host/some_path"); Part[] parts = { new StringPart("param_name", "value"), new FilePart(f.getName(), f) }; filePost.setRequestEntity( new MultipartRequestEntity(parts, filePost.getParams()) ); HttpClient client = new HttpClient(); int status = client.executeMethod(filePost);
@Override void configureRequest(PostMethod method) throws IOException { Part[] parts = new Part[] { new FilePart("bundle", new ByteArrayPartSource("bundle.jar", IOUtils.toByteArray(jarredBundle))) }; method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams())); } }.installBundle();