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.
GetMethod method = new GetMethod("example.com/page"); method.setQueryString(new NameValuePair[] { new NameValuePair("key", "value") });
/** * Adds a new parameter to be used in the POST request body. * * @param paramName The parameter name to add. * @param paramValue The parameter value to add. * * @throws IllegalArgumentException if either argument is null * * @since 1.0 */ public void addParameter(String paramName, String paramValue) throws IllegalArgumentException { LOG.trace("enter PostMethod.addParameter(String, String)"); if ((paramName == null) || (paramValue == null)) { throw new IllegalArgumentException( "Arguments to addParameter(String, String) cannot be null"); } super.clearRequestBody(); this.params.add(new NameValuePair(paramName, paramValue)); }
/** * Return a string suitable for sending in a <tt>"Cookie"</tt> header as * defined in RFC 2109 * @param cookie a {@link Cookie} to be formatted as string * @return a string suitable for sending in a <tt>"Cookie"</tt> header. */ public String formatCookie(Cookie cookie) { LOG.trace("enter RFC2109Spec.formatCookie(Cookie)"); if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } int version = cookie.getVersion(); StringBuffer buffer = new StringBuffer(); formatParam(buffer, new NameValuePair("$Version", Integer.toString(version)), version); buffer.append("; "); formatCookieAsVer(buffer, cookie, version); return buffer.toString(); }
public Header getVersionHeader() { ParameterFormatter formatter = new ParameterFormatter(); StringBuffer buffer = new StringBuffer(); formatter.format(buffer, new NameValuePair("$Version", Integer.toString(getVersion()))); return new Header("Cookie2", buffer.toString(), true); }
params.add(new NameValuePair("username", uname)); params.add(new NameValuePair("realm", realm)); params.add(new NameValuePair("nonce", nonce)); params.add(new NameValuePair("uri", uri)); params.add(new NameValuePair("response", response)); params.add(new NameValuePair("qop", getQopVariantString())); params.add(new NameValuePair("nc", NC)); params.add(new NameValuePair("cnonce", this.cnonce)); params.add(new NameValuePair("algorithm", algorithm)); params.add(new NameValuePair("opaque", opaque));
/** * Return a string suitable for sending in a <tt>"Cookie"</tt> header as * defined in RFC 2965 * @param cookie a {@link org.apache.commons.httpclient.Cookie} to be formatted as string * @return a string suitable for sending in a <tt>"Cookie"</tt> header. */ public String formatCookie(final Cookie cookie) { LOG.trace("enter RFC2965Spec.formatCookie(Cookie)"); if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (cookie instanceof Cookie2) { Cookie2 cookie2 = (Cookie2) cookie; int version = cookie2.getVersion(); final StringBuffer buffer = new StringBuffer(); this.formatter.format(buffer, new NameValuePair("$Version", Integer.toString(version))); buffer.append("; "); doFormatCookie2(cookie2, buffer); return buffer.toString(); } else { // old-style cookies are formatted according to the old rules return this.rfc2109.formatCookie(cookie); } }
/** * Create a RFC 2109 compliant <tt>"Cookie"</tt> header value containing all * {@link Cookie}s in <i>cookies</i> suitable for sending in a <tt>"Cookie" * </tt> header * @param cookies an array of {@link Cookie}s to be formatted * @return a string suitable for sending in a Cookie header. */ public String formatCookies(Cookie[] cookies) { LOG.trace("enter RFC2109Spec.formatCookieHeader(Cookie[])"); int version = Integer.MAX_VALUE; // Pick the lowerest common denominator for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if (cookie.getVersion() < version) { version = cookie.getVersion(); } } final StringBuffer buffer = new StringBuffer(); formatParam(buffer, new NameValuePair("$Version", Integer.toString(version)), version); for (int i = 0; i < cookies.length; i++) { buffer.append("; "); formatCookieAsVer(buffer, cookies[i], version); } return buffer.toString(); }
this.formatter.format(buffer, new NameValuePair("$Version", Integer.toString(version))); for (int i = 0; i < cookies.length; i++) { buffer.append("; ");
/** * Return a string suitable for sending in a <tt>"Cookie"</tt> header * as defined in RFC 2109 for backward compatibility with cookie version 0 * @param buffer The string buffer to use for output * @param cookie The {@link Cookie} to be formatted as string * @param version The version to use. */ private void formatCookieAsVer(final StringBuffer buffer, final Cookie cookie, int version) { String value = cookie.getValue(); if (value == null) { value = ""; } formatParam(buffer, new NameValuePair(cookie.getName(), value), version); if ((cookie.getPath() != null) && cookie.isPathAttributeSpecified()) { buffer.append("; "); formatParam(buffer, new NameValuePair("$Path", cookie.getPath()), version); } if ((cookie.getDomain() != null) && cookie.isDomainAttributeSpecified()) { buffer.append("; "); formatParam(buffer, new NameValuePair("$Domain", cookie.getDomain()), version); } }
params.add(new NameValuePair(paramName, paramValue));
private void doFormatCookie2(final Cookie2 cookie, final StringBuffer buffer) { String name = cookie.getName(); String value = cookie.getValue(); if (value == null) { value = ""; } this.formatter.format(buffer, new NameValuePair(name, value)); // format domain attribute if (cookie.getDomain() != null && cookie.isDomainAttributeSpecified()) { buffer.append("; "); this.formatter.format(buffer, new NameValuePair("$Domain", cookie.getDomain())); } // format path attribute if ((cookie.getPath() != null) && (cookie.isPathAttributeSpecified())) { buffer.append("; "); this.formatter.format(buffer, new NameValuePair("$Path", cookie.getPath())); } // format port attribute if (cookie.isPortAttributeSpecified()) { String portValue = ""; if (!cookie.isPortAttributeBlank()) { portValue = createPortAttribute(cookie.getPorts()); } buffer.append("; "); this.formatter.format(buffer, new NameValuePair("$Port", portValue)); } }
NameValuePair nvp1= new NameValuePair("firstName","fname"); NameValuePair nvp2= new NameValuePair("lastName","lname"); NameValuePair nvp3= new NameValuePair("email","email@email.com");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(parameters.size()); for (Entry<String, String> e : parameters.entrySet()) { nameValuePairs.add(new NameValuePair(e.getKey(), e.getValue()));
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(parameters.size()); for (Entry<String, String> e : parameters.entrySet()) { nameValuePairs.add(new NameValuePair(e.getKey(), e.getValue()));
protected NameValuePair[] buildPathQueryArgs(String appPath) { if (!appPath.startsWith("/")) { appPath = "/" + appPath; } return new NameValuePair[] { new NameValuePair("path", appPath)}; }
/** * {@inheritDoc} */ public NameValuePair[] getSubmitKeyValuePairs() { String text = getText(); text = text.replace("\r\n", "\n").replace("\n", "\r\n"); return new NameValuePair[]{new NameValuePair(getNameAttribute(), text)}; }
public Set<String> loggerPatterns() throws IOException { final GetMethod method = new GetMethod(getUrl()); method.setQueryString(new NameValuePair[]{new NameValuePair("o", "loggersConfig")}); final String content = executeAndGetContent(method); final Type type = new TypeToken<Collection<LoggerPatternsResponse>>() { }.getType(); final List<LoggerPatternsResponse> o = new Gson().fromJson(content, type); return o.stream().flatMap(patterns -> patterns.getPatterns().stream()).collect(Collectors.toSet()); }
/** * {@inheritDoc} */ public NameValuePair[] getSubmitKeyValuePairs() { return new NameValuePair[]{new NameValuePair(getPromptAttribute(), getValue())}; }
// Create client with settings final WebClient webClient = new WebClient(); webClient.setTimeout(5000); // Create web request WebRequest requestSettings = new WebRequest(new URL("http://www.amazon.com/s/ref=nb_sb_noss"), HttpMethod.POST); // Set the request parameters requestSettings.setRequestParameters(new ArrayList()); requestSettings.getRequestParameters().add(new NameValuePair("field-keywords", "Doctor Who")); Page page = webClient.getPage(requestSettings); page.getWebResponse().getStatusCode();