/** * Sets the value of parameter with parameterName to parameterValue. This method * does not preserve the initial insertion order. * * @param parameterName name of the parameter * @param parameterValue value of the parameter * * @since 2.0 */ public void setParameter(String parameterName, String parameterValue) { LOG.trace("enter PostMethod.setParameter(String, String)"); removeParameter(parameterName); addParameter(parameterName, parameterValue); }
/** * Adds a new parameter to be used in the POST request body. * * @param param The parameter to add. * * @throws IllegalArgumentException if the argument is null or contains * null values * * @since 2.0 */ public void addParameter(NameValuePair param) throws IllegalArgumentException { LOG.trace("enter PostMethod.addParameter(NameValuePair)"); if (param == null) { throw new IllegalArgumentException("NameValuePair may not be null"); } addParameter(param.getName(), param.getValue()); }
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.http.impl.client.HttpClients; public class PostReqEx { public void sendReq(String url,String email,String fname){ HttpClient httpClient = HttpClients.createDefault(); PostMethod postMethod = new PostMethod(url); postMethod.addParameter("Email", email); postMethod.addParameter("fname", fname); try { httpClient.executeMethod(postMethod); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (postMethod.getStatusCode() == HttpStatus.SC_OK) { String resp = postMethod.getResponseBodyAsString(); } else { //...postMethod.getStatusLine(); } } }
/** * Register a schema to the Kafka schema registry under the provided input name. This method will change the name * of the schema to the provided name if configured to do so. This is useful because certain services (like Gobblin kafka adaptor and * Camus) get the schema for a topic by querying for the latest schema with the topic name, requiring the topic * name and schema name to match for all topics. If it is not configured to switch names, this is useful for the case * where the Kafka topic and Avro schema names do not match. This method registers the schema to the schema registry in such a * way that any schema can be written to any topic. * * @param schema {@link org.apache.avro.Schema} to register. * @param name Name of the schema when registerd to the schema registry. This name should match the name * of the topic where instances will be published. * @return schema ID of the registered schema. * @throws SchemaRegistryException if registration failed */ @Override public MD5Digest register(String name, Schema schema) throws SchemaRegistryException { PostMethod post = new PostMethod(url); if (this.switchTopicNames) { return register(AvroUtils.switchName(schema, name), post); } else { post.addParameter("name", name); return register(schema, post); } }
post.addParameter("schema", schema.toString());
post.addParameter("schema", schema.toString());
@Override public boolean ping(final String callingPeer) throws RemoteException { if (s_logger.isDebugEnabled()) { s_logger.debug("Ping at " + _serviceUrl); } final HttpClient client = getHttpClient(); final PostMethod method = new PostMethod(_serviceUrl); method.addParameter("method", Integer.toString(RemoteMethodConstants.METHOD_PING)); method.addParameter("callingPeer", callingPeer); final String returnVal = executePostMethod(client, method); if ("true".equalsIgnoreCase(returnVal)) { return true; } return false; }
@Override public String execute(final ClusterServicePdu pdu) throws RemoteException { final HttpClient client = getHttpClient(); final PostMethod method = new PostMethod(_serviceUrl); method.addParameter("method", Integer.toString(RemoteMethodConstants.METHOD_DELIVER_PDU)); method.addParameter("sourcePeer", pdu.getSourcePeer()); method.addParameter("destPeer", pdu.getDestPeer()); method.addParameter("pduSeq", Long.toString(pdu.getSequenceId())); method.addParameter("pduAckSeq", Long.toString(pdu.getAckSequenceId())); method.addParameter("agentId", Long.toString(pdu.getAgentId())); method.addParameter("gsonPackage", pdu.getJsonPackage()); method.addParameter("stopOnError", pdu.isStopOnError() ? "1" : "0"); method.addParameter("pduType", Integer.toString(pdu.getPduType())); return executePostMethod(client, method); }
method.addParameter("p", "apple");
@Override void configureRequest(PostMethod method) { method.addParameter("dir", explodedBundleLocation); } }.installBundle();
public PostMethod postMethod() { final PostMethod postMethod = new PostMethod(targetURL); postMethod.addParameter("host", host); postMethod.addParameter("port", port); postMethod.addParameter("environment", environment); return postMethod; }
public PostMethod postMethod() { final PostMethod postMethod = new PostMethod(targetURL); postMethod.addParameter("host", host); postMethod.addParameter("port", port); postMethod.addParameter("environment", environment); return postMethod; }
private PostMethod setupPostMethod() { final PostMethod m = new PostMethod(HIPCHAT_API_URL + apiToken); m.setRequestHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED + "; charset=UTF-8"); m.addParameter("room_id", room); m.addParameter("from", from); m.addParameter("notify", (notify ? "1" : "0")); return m; }
private boolean loginLegacy(String username, String password) throws IOException { PostMethod request = new PostMethod(getBaseUrl() + LEGACY_PATH); request.addParameter(LEGACY_PARAM_USERID, username); request.addParameter(LEGACY_PARAM_PASSWORD, password); request.addParameter(LEGACY_PARAM_WORKSPACE, LEGACY_VALUE_WORKSPACE); request.addParameter(LEGACY_PARAM_TOKEN, LEGACY_VALUE_TOKEN); request.addParameter(LOGIN_PARAM_CHARSET, LOGIN_VALUE_CHARSET); return getClient().executeMethod(request) == 200; }
/** * Gets the latest commit version and generation from the master */ @SuppressWarnings("unchecked") NamedList getLatestVersion() throws IOException { PostMethod post = new PostMethod(masterUrl); post.addParameter(COMMAND, CMD_INDEX_VERSION); post.addParameter("wt", "javabin"); return getNamedListResponse(post); }
NamedList getCommandResponse(NamedList<String> commands) throws IOException { PostMethod post = new PostMethod(masterUrl); for (Map.Entry<String, String> c : commands) { post.addParameter(c.getKey(),c.getValue()); } post.addParameter("wt", "javabin"); return getNamedListResponse(post); }
public int post(String url, Map<String,String> properties) throws HttpException, IOException { final PostMethod post = new PostMethod(url); post.getParams().setContentCharset("UTF-8"); for(Entry<String, String> e : properties.entrySet()) { post.addParameter(e.getKey(), e.getValue()); } return httpClient.executeMethod(post); }
private void addApiKey(PostMethod post) { if (propertiesManager.getKey() == null) { throw new IllegalStateException("Please set your key before using this tool. Use the -s key <key> option."); } else { post.addParameter("apiKey", propertiesManager.getKey()); } }
HttpClient hc = new HttpClient(); PostMethod pm = new PostMethod(url); // add parameters to it. pm.addParameter("format","json"); hc.executeMethod(pm);
HttpClient http = new HttpClient(); http.setParams(new HttpClientParams()); http.setState(new HttpState()); //For Get GetMethod get = new GetMethod("http://www.something.com/myscript?param="+paramVar); http.executeMethod(get); // For Post PostMethod post = new PostMethod("http://www.something.com/myscript"); post.addParameter("param", paramVar); http.executeMethod(post);