org.apache.commons.httpclient.NameValuePair.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中org.apache.commons.httpclient.NameValuePair.<init>()方法的一些代码示例,展示了NameValuePair.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NameValuePair.<init>()方法的具体详情如下:
包路径:org.apache.commons.httpclient.NameValuePair
类名称:NameValuePair
方法名:<init>

NameValuePair.<init>介绍

[英]Default constructor.
[中]默认构造函数。

代码示例

代码示例来源:origin: stackoverflow.com

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.

代码示例来源:origin: stackoverflow.com

GetMethod method = new GetMethod("example.com/page"); 
method.setQueryString(new NameValuePair[] { 
  new NameValuePair("key", "value") 
});

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * 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));
}

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * 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();
}

代码示例来源:origin: commons-httpclient/commons-httpclient

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);
}

代码示例来源:origin: commons-httpclient/commons-httpclient

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));

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * 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);
  }
}

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * 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();
}

代码示例来源:origin: commons-httpclient/commons-httpclient

this.formatter.format(buffer, new NameValuePair("$Version", Integer.toString(version)));
for (int i = 0; i < cookies.length; i++) {
  buffer.append("; ");

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * 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);
  }
}

代码示例来源:origin: commons-httpclient/commons-httpclient

params.add(new NameValuePair(paramName, paramValue));

代码示例来源:origin: commons-httpclient/commons-httpclient

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));
  }
}

代码示例来源:origin: stackoverflow.com

NameValuePair nvp1= new NameValuePair("firstName","fname");
NameValuePair nvp2= new NameValuePair("lastName","lname");
NameValuePair nvp3= new NameValuePair("email","email@email.com");

代码示例来源:origin: apache/cloudstack

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(parameters.size());
for (Entry<String, String> e : parameters.entrySet()) {
  nameValuePairs.add(new NameValuePair(e.getKey(), e.getValue()));

代码示例来源:origin: apache/cloudstack

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(parameters.size());
for (Entry<String, String> e : parameters.entrySet()) {
  nameValuePairs.add(new NameValuePair(e.getKey(), e.getValue()));

代码示例来源:origin: org.apache.portals.jetspeed-2/jetspeed-portal

protected NameValuePair[] buildPathQueryArgs(String appPath)
{
  if (!appPath.startsWith("/"))
  {
    appPath = "/" + appPath;
  }
  return new NameValuePair[] { new NameValuePair("path", appPath)};
}

代码示例来源:origin: org.jenkins-ci/htmlunit

/**
 * {@inheritDoc}
 */
public NameValuePair[] getSubmitKeyValuePairs() {
  String text = getText();
  text = text.replace("\r\n", "\n").replace("\n", "\r\n");
  return new NameValuePair[]{new NameValuePair(getNameAttribute(), text)};
}

代码示例来源:origin: otros-systems/otroslogviewer

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());
}

代码示例来源:origin: org.jvnet.hudson/htmlunit

/**
 * {@inheritDoc}
 */
public NameValuePair[] getSubmitKeyValuePairs() {
  return new NameValuePair[]{new NameValuePair(getPromptAttribute(), getValue())};
}

代码示例来源:origin: stackoverflow.com

// 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();

相关文章