PostMethod post=new PostMethod(url); for (Entry<String, String> entry : map.entrySet()) { post.setParameter(entry.getKey(), entry.getValue()); }
protected void addHttpPostParams(Map<String, String> values, PostMethod method) { for (String key : values.keySet()) { String parameterValue = values.get(key); parameterValue = parameterValue != null ? parameterValue : NULL; method.setParameter(key, parameterValue); } }
PostMethod method = new PostMethod(URIUtil.encodePath("http://localhost:8080/Assignment/rest/words/{name}/protection", "UTF-8")); method.setParameter("name", "value");
/** * Performs the service request "CloseSession". * * @exception ClientException * if something went wrong during the request * @exception ServiceException * if the response is of MIME type <code>application/vnd.ogc.se_xml */ public void closeSession(String version, String sessionID) throws ServiceException, ClientException { PostMethod postMethod = new PostMethod(wasURLString); postMethod.setParameter("VERSION", version); postMethod.setParameter("REQUEST", "CloseSession"); postMethod.setParameter("SESSIONID", sessionID); try { client.executeMethod(postMethod); } catch (IOException ioe) { throw new ClientException("I/O exception during CLOSESESSION request to Authentication Service:", ioe); } finally { postMethod.releaseConnection(); } }
public String postUrl(String url, Map<String, ?> parameter) { PostMethod post = new PostMethod(url); if (parameter != null) { for (String key : parameter.keySet()) { Object value = parameter.get(key); if (value.getClass().isArray()) { Object[] arrayValue = (Object[]) value; for (Object o : arrayValue) { post.addParameter(key, o.toString()); } } else { post.setParameter(key, value.toString()); } } } return execute(post); }
HttpClient c = new HttpClient(); String url = "http://" + cargoHost + ":" + cargoPort + contextPath + "/j_security_check"; PostMethod post = new PostMethod(url); post.setParameter("j_username", username); post.setParameter("j_password", password); c.executeMethod(post); url = "http://" + cargoHost + ":" + cargoPort + contextPath + "/myurl.html"; MultipartPostMethod mPost = new MultipartPostMethod(url); String fileNameWithPath = this.getClass().getClassLoader().getResource(filename).getPath(); File f1 = new File(fileNameWithPath); mPost.addParameter(elementName, f1); mPost.addParameter("action", "upload"); mPost.addParameter("ajax", "true"); c.executeMethod(mPost); mPost.getResponseBodyAsString();
private void addBodyParameters(PostMethod postMethod, List<String> recipients, String message) { Map<String, String> bodyParameters = outgoing.getRequest().getBodyParameters(); for (Map.Entry<String,String> entry: bodyParameters.entrySet()) { String value = placeHolderOrLiteral(entry.getValue(), recipients, message); postMethod.setParameter(entry.getKey(), value); } }
public String postUrl(String url, Map<String, ?> parameter) { PostMethod post = new PostMethod(url); if (parameter != null) { for (String key : parameter.keySet()) { Object value = parameter.get(key); if (value.getClass().isArray()) { Object[] arrayValue = (Object[]) value; for (Object o : arrayValue) { post.addParameter(key, o.toString()); } } else { post.setParameter(key, value.toString()); } } } addHeader(post, headerMap); return execute(post); }
public void setParameters(PostMethod httpMethod) { httpMethod.setParameter("superflyLogoutSessionIds", StringUtils.collectionToCommaDelimitedString(notification.getSessionIds())); } });
public String executePost(String url, Map<String, String> parameters, IProgressMonitor monitor) throws ReviewboardException { PostMethod postRequest = new PostMethod(stripSlash(location.getUrl()) + url); configureRequestForJson(postRequest); for (Map.Entry<String, String> entry : parameters.entrySet()) postRequest.setParameter(entry.getKey(), entry.getValue()); return executeMethod(postRequest, monitor); }
protected PostMethod buildPostMethod(String url, HttpParameters parameters) { final PostMethod postMethod; postMethod = new PostMethod(url); postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; ; charset=UTF-8"); for (String name : parameters.names()) { postMethod.setParameter(name, parameters.get(name)); } return postMethod; }
protected PostMethod buildPostMethod(String url, HttpParameters parameters) { final PostMethod postMethod; postMethod = new PostMethod(url); postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; ; charset=UTF-8"); for (String name : parameters.names()) { postMethod.setParameter(name, parameters.get(name)); } return postMethod; }
File file = new File("FileToSend.txt"); HttpClient client = new HttpClient(); String url = "http://www.yourdomain.com/destination.php"; PostMethod postMethod = new PostMethod(url); Part[] parts = {new FilePart(file.getName(), file)}; postMethod.setParameter("name", "value"); // set parameters like this instead in separate call postMethod.setRequestEntity( new MultipartRequestEntity(parts, postMethod.getParams())); int status = client.executeMethod(postMethod);
protected PostMethod buildPostMethod(String url, HttpParameters parameters) { final PostMethod postMethod; postMethod = new PostMethod(url); postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; ; charset=UTF-8"); for (String name : parameters.names()) { postMethod.setParameter(name, parameters.get(name)); } return postMethod; }
@Override public HTTPServerResponse dispatch(Method method) throws DispatcherException { HttpClient httpClient = new HttpClient(); PostMethod postMethod = new PostMethod(url); postMethod.setParameter(REQUEST_PARAM_CLASS_NAME, method.getDeclaringClass().getCanonicalName()); postMethod.setParameter(REQUEST_PARAM_METHOD_NAME, method.getName()); try { try { httpClient.executeMethod(postMethod); } catch (ConnectException ex) { throw new DispatcherException("Failed to connect to \"" + url + "\". Seems like server is down"); } return new HTTPServerResponse(url, postMethod.getResponseBodyAsString(), postMethod.getStatusCode()); } catch (IOException e) { throw new DispatcherException("Exception caught while sending request to \"" + url + "\"", e); } finally { postMethod.releaseConnection(); } } }
public class MailServiceHelper { public String getJsp(String url, Map<String,String> form, HttpServletRequest request) { //we can figure out the base url from the request String baseUrl =""; HttpClient client = new HttpClient(); PostMethod method = new PostMethod(baseUrl+"/"+url); for (String formElement : form.keySet()) { method.setParameter(formElement, form.get(formElement)); } try { int statusCode = client.executeMethod(method); if (statusCode >= HttpStatus.SC_OK && statusCode < HttpStatus.SC_MULTIPLE_CHOICES) { byte[] responseBody = method.getResponseBody(); return new String(responseBody,StandardCharsets.UTF_8); }else{ throw new RuntimeException("Failed to read jsp, server returened with status code: "+statusCode); } } catch (Exception e) { throw new RuntimeException("Failed to read jsp",e); }finally{ method.releaseConnection(); } }
protected void doCall(String uri, String notificationType, ParameterSetter parameterSetter) throws NotificationException { PostMethod httpMethod = new PostMethod(uri); httpMethod.setParameter("superflyNotification", notificationType); parameterSetter.setParameters(httpMethod); try { httpClient.executeMethod(httpMethod); if (logger.isInfoEnabled()) { logger.info("Successfully notified " + uri + " with params " + Arrays.asList(httpMethod.getParameters())); } } catch (HttpException e) { throw new NotificationException(e); } catch (IOException e) { throw new NotificationException(e); } finally { try { httpMethod.releaseConnection(); } catch (IllegalArgumentException ignored) { logger.warn(ignored.getMessage(), ignored); } } }
PostMethod post = new PostMethod(server.getUrl()); post.setParameter("XMLString", query); post.setRequestContentLength(PostMethod.CONTENT_LENGTH_AUTO); post.setStrictMode(true); try { client.executeMethod(post); return post.getResponseBodyAsString(); } finally { post.releaseConnection(); }
@Override public void sendNotification(Notification notification) { String message = (notification instanceof Notification.HtmlImContentProvidingNotification) ? ((Notification.HtmlImContentProvidingNotification) notification).getHtmlImContent() : notification.getIMContent(); if (!StringUtils.isEmpty(message)) { PostMethod method = setupPostMethod(); method.setParameter("message", message); if (resultsSummary != null) { setMessageColor(method, resultsSummary); } else if (deploymentResult != null) { setMessageColor(method, deploymentResult); } else { setMessageColor(method, COLOR_UNKNOWN_STATE); //todo: might need to use different color in some cases } try { client.executeMethod(method); } catch (IOException e) { log.error("Error using Hipchat API: " + e.getMessage(), e); } } }
/** * Get token * * @throws Exception in case of an IO error */ public void getToken() throws IOException { PostMethod m = new PostMethod("/services/tokens/active"); m.getParams().setCookiePolicy(CookiePolicy.NETSCAPE); m.setParameter("username", getUserName()); m.setParameter("password", getPassword()); try { client.executeMethod(m); System.err.println(m.getResponseBodyAsString()); if (m.getStatusCode() != HttpStatus.SC_OK && m.getStatusCode() != HttpStatus.SC_MOVED_TEMPORARILY) { throw new InvalidParameterException("Invalid PT credentials. HTTP reply code " + m.getStatusCode()); } } finally { m.releaseConnection(); } }