本文整理汇总了Java中org.apache.commons.httpclient.NameValuePair.getName方法的典型用法代码示例。如果您正苦于以下问题:Java NameValuePair.getName方法的具体用法?Java NameValuePair.getName怎么用?Java NameValuePair.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.NameValuePair
的用法示例。
在下文中一共展示了NameValuePair.getName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseAttribute
import org.apache.commons.httpclient.NameValuePair; //导入方法依赖的package包/类
/**
* Parse RFC 2965 specific cookie attribute and update the corresponsing
* {@link org.apache.commons.httpclient.Cookie} properties.
*
* @param attribute {@link org.apache.commons.httpclient.NameValuePair} cookie attribute from the
* <tt>Set-Cookie2</tt> header.
* @param cookie {@link org.apache.commons.httpclient.Cookie} to be updated
* @throws MalformedCookieException if an exception occurs during parsing
*/
public void parseAttribute(
final NameValuePair attribute, final Cookie cookie)
throws MalformedCookieException {
if (attribute == null) {
throw new IllegalArgumentException("Attribute may not be null.");
}
if (attribute.getName() == null) {
throw new IllegalArgumentException("Attribute Name may not be null.");
}
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null.");
}
final String paramName = attribute.getName().toLowerCase();
final String paramValue = attribute.getValue();
CookieAttributeHandler handler = findAttribHandler(paramName);
if (handler == null) {
// ignore unknown attribute-value pairs
if (LOG.isDebugEnabled())
LOG.debug("Unrecognized cookie attribute: " +
attribute.toString());
} else {
handler.parse(cookie, paramValue);
}
}
示例2: doFormUrlEncode
import org.apache.commons.httpclient.NameValuePair; //导入方法依赖的package包/类
/**
* Form-urlencoding routine.
*
* The default encoding for all forms is `application/x-www-form-urlencoded'.
* A form data set is represented in this media type as follows:
*
* The form field names and values are escaped: space characters are replaced
* by `+', and then reserved characters are escaped as per [URL]; that is,
* non-alphanumeric characters are replaced by `%HH', a percent sign and two
* hexadecimal digits representing the ASCII code of the character. Line breaks,
* as in multi-line text field values, are represented as CR LF pairs, i.e. `%0D%0A'.
*
* @param pairs the values to be encoded
* @param charset the character set of pairs to be encoded
*
* @return the urlencoded pairs
* @throws UnsupportedEncodingException if charset is not supported
*
* @since 2.0 final
*/
private static String doFormUrlEncode(NameValuePair[] pairs, String charset)
throws UnsupportedEncodingException
{
StringBuffer buf = new StringBuffer();
for (int i = 0; i < pairs.length; i++) {
URLCodec codec = new URLCodec();
NameValuePair pair = pairs[i];
if (pair.getName() != null) {
if (i > 0) {
buf.append("&");
}
buf.append(codec.encode(pair.getName(), charset));
buf.append("=");
if (pair.getValue() != null) {
buf.append(codec.encode(pair.getValue(), charset));
}
}
}
return buf.toString();
}