michael@0: /* michael@0: * ==================================================================== michael@0: * michael@0: * Licensed to the Apache Software Foundation (ASF) under one or more michael@0: * contributor license agreements. See the NOTICE file distributed with michael@0: * this work for additional information regarding copyright ownership. michael@0: * The ASF licenses this file to You under the Apache License, Version 2.0 michael@0: * (the "License"); you may not use this file except in compliance with michael@0: * the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: * ==================================================================== michael@0: * michael@0: * This software consists of voluntary contributions made by many michael@0: * individuals on behalf of the Apache Software Foundation. For more michael@0: * information on the Apache Software Foundation, please see michael@0: * . michael@0: * michael@0: */ michael@0: michael@0: package ch.boye.httpclientandroidlib.client.entity; michael@0: michael@0: import java.io.UnsupportedEncodingException; michael@0: import java.util.List; michael@0: michael@0: import ch.boye.httpclientandroidlib.annotation.NotThreadSafe; michael@0: michael@0: import ch.boye.httpclientandroidlib.NameValuePair; michael@0: import ch.boye.httpclientandroidlib.client.utils.URLEncodedUtils; michael@0: import ch.boye.httpclientandroidlib.entity.StringEntity; michael@0: import ch.boye.httpclientandroidlib.protocol.HTTP; michael@0: michael@0: /** michael@0: * An entity composed of a list of url-encoded pairs. michael@0: * This is typically useful while sending an HTTP POST request. michael@0: * michael@0: * @since 4.0 michael@0: */ michael@0: @NotThreadSafe // AbstractHttpEntity is not thread-safe michael@0: public class UrlEncodedFormEntity extends StringEntity { michael@0: michael@0: /** michael@0: * Constructs a new {@link UrlEncodedFormEntity} with the list michael@0: * of parameters in the specified encoding. michael@0: * michael@0: * @param parameters list of name/value pairs michael@0: * @param encoding encoding the name/value pairs be encoded with michael@0: * @throws UnsupportedEncodingException if the encoding isn't supported michael@0: */ michael@0: public UrlEncodedFormEntity ( michael@0: final List parameters, michael@0: final String encoding) throws UnsupportedEncodingException { michael@0: super(URLEncodedUtils.format(parameters, encoding), encoding); michael@0: setContentType(URLEncodedUtils.CONTENT_TYPE + HTTP.CHARSET_PARAM + michael@0: (encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET)); michael@0: } michael@0: michael@0: /** michael@0: * Constructs a new {@link UrlEncodedFormEntity} with the list michael@0: * of parameters with the default encoding of {@link HTTP#DEFAULT_CONTENT_CHARSET} michael@0: * michael@0: * @param parameters list of name/value pairs michael@0: * @throws UnsupportedEncodingException if the default encoding isn't supported michael@0: */ michael@0: public UrlEncodedFormEntity ( michael@0: final List parameters) throws UnsupportedEncodingException { michael@0: this(parameters, HTTP.DEFAULT_CONTENT_CHARSET); michael@0: } michael@0: michael@0: }