use of org.apache.http.NameValuePair in project XobotOS by xamarin.
the class BasicHeaderValueParser method parseHeaderElement.
// non-javadoc, see interface HeaderValueParser
public HeaderElement parseHeaderElement(final CharArrayBuffer buffer, final ParserCursor cursor) {
if (buffer == null) {
throw new IllegalArgumentException("Char array buffer may not be null");
}
if (cursor == null) {
throw new IllegalArgumentException("Parser cursor may not be null");
}
NameValuePair nvp = parseNameValuePair(buffer, cursor);
NameValuePair[] params = null;
if (!cursor.atEnd()) {
char ch = buffer.charAt(cursor.getPos() - 1);
if (ch != ELEM_DELIMITER) {
params = parseParameters(buffer, cursor);
}
}
return createHeaderElement(nvp.getName(), nvp.getValue(), params);
}
use of org.apache.http.NameValuePair in project xUtils by wyouflf.
the class OtherUtils method getCharsetFromHttpRequest.
public static Charset getCharsetFromHttpRequest(final HttpRequestBase request) {
if (request == null)
return null;
String charsetName = null;
Header header = request.getFirstHeader("Content-Type");
if (header != null) {
for (HeaderElement element : header.getElements()) {
NameValuePair charsetPair = element.getParameterByName("charset");
if (charsetPair != null) {
charsetName = charsetPair.getValue();
break;
}
}
}
boolean isSupportedCharset = false;
if (!TextUtils.isEmpty(charsetName)) {
try {
isSupportedCharset = Charset.isSupported(charsetName);
} catch (Throwable e) {
}
}
return isSupportedCharset ? Charset.forName(charsetName) : null;
}
use of org.apache.http.NameValuePair in project xUtils by wyouflf.
the class URLEncodedUtils method format.
/**
* Returns a String that is suitable for use as an <code>application/x-www-form-urlencoded</code>
* list of parameters in an HTTP PUT or HTTP POST.
*
* @param parameters The parameters to include.
* @param charset The encoding to use.
* @since 4.2
*/
public static String format(final Iterable<? extends NameValuePair> parameters, final Charset charset) {
final StringBuilder result = new StringBuilder();
for (final NameValuePair parameter : parameters) {
final String encodedName = encodeFormFields(parameter.getName(), charset);
final String encodedValue = encodeFormFields(parameter.getValue(), charset);
if (result.length() > 0) {
result.append(PARAMETER_SEPARATOR);
}
result.append(encodedName);
if (encodedValue != null) {
result.append(NAME_VALUE_SEPARATOR);
result.append(encodedValue);
}
}
return result.toString();
}
use of org.apache.http.NameValuePair in project xUtils by wyouflf.
the class URIBuilder method addParameter.
/**
* Adds parameter to URI query. The parameter name and value are expected to be unescaped
* and may contain non ASCII characters.
*/
public URIBuilder addParameter(final String param, final String value) {
if (this.queryParams == null) {
this.queryParams = new ArrayList<NameValuePair>();
}
this.queryParams.add(new BasicNameValuePair(param, value));
this.encodedQuery = null;
this.encodedSchemeSpecificPart = null;
return this;
}
use of org.apache.http.NameValuePair in project xUtils by wyouflf.
the class URIBuilder method setParameter.
/**
* Sets parameter of URI query overriding existing value if set. The parameter name and value
* are expected to be unescaped and may contain non ASCII characters.
*/
public URIBuilder setParameter(final String param, final String value) {
if (this.queryParams == null) {
this.queryParams = new ArrayList<NameValuePair>();
}
if (!this.queryParams.isEmpty()) {
for (final Iterator<NameValuePair> it = this.queryParams.iterator(); it.hasNext(); ) {
final NameValuePair nvp = it.next();
if (nvp.getName().equals(param)) {
it.remove();
}
}
}
this.queryParams.add(new BasicNameValuePair(param, value));
this.encodedQuery = null;
this.encodedSchemeSpecificPart = null;
return this;
}
Aggregations