|
1 /* |
|
2 * ==================================================================== |
|
3 * |
|
4 * Licensed to the Apache Software Foundation (ASF) under one or more |
|
5 * contributor license agreements. See the NOTICE file distributed with |
|
6 * this work for additional information regarding copyright ownership. |
|
7 * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
8 * (the "License"); you may not use this file except in compliance with |
|
9 * the License. You may obtain a copy of the License at |
|
10 * |
|
11 * http://www.apache.org/licenses/LICENSE-2.0 |
|
12 * |
|
13 * Unless required by applicable law or agreed to in writing, software |
|
14 * distributed under the License is distributed on an "AS IS" BASIS, |
|
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
16 * See the License for the specific language governing permissions and |
|
17 * limitations under the License. |
|
18 * ==================================================================== |
|
19 * |
|
20 * This software consists of voluntary contributions made by many |
|
21 * individuals on behalf of the Apache Software Foundation. For more |
|
22 * information on the Apache Software Foundation, please see |
|
23 * <http://www.apache.org/>. |
|
24 * |
|
25 */ |
|
26 |
|
27 package ch.boye.httpclientandroidlib.client.entity; |
|
28 |
|
29 import java.io.UnsupportedEncodingException; |
|
30 import java.util.List; |
|
31 |
|
32 import ch.boye.httpclientandroidlib.annotation.NotThreadSafe; |
|
33 |
|
34 import ch.boye.httpclientandroidlib.NameValuePair; |
|
35 import ch.boye.httpclientandroidlib.client.utils.URLEncodedUtils; |
|
36 import ch.boye.httpclientandroidlib.entity.StringEntity; |
|
37 import ch.boye.httpclientandroidlib.protocol.HTTP; |
|
38 |
|
39 /** |
|
40 * An entity composed of a list of url-encoded pairs. |
|
41 * This is typically useful while sending an HTTP POST request. |
|
42 * |
|
43 * @since 4.0 |
|
44 */ |
|
45 @NotThreadSafe // AbstractHttpEntity is not thread-safe |
|
46 public class UrlEncodedFormEntity extends StringEntity { |
|
47 |
|
48 /** |
|
49 * Constructs a new {@link UrlEncodedFormEntity} with the list |
|
50 * of parameters in the specified encoding. |
|
51 * |
|
52 * @param parameters list of name/value pairs |
|
53 * @param encoding encoding the name/value pairs be encoded with |
|
54 * @throws UnsupportedEncodingException if the encoding isn't supported |
|
55 */ |
|
56 public UrlEncodedFormEntity ( |
|
57 final List <? extends NameValuePair> parameters, |
|
58 final String encoding) throws UnsupportedEncodingException { |
|
59 super(URLEncodedUtils.format(parameters, encoding), encoding); |
|
60 setContentType(URLEncodedUtils.CONTENT_TYPE + HTTP.CHARSET_PARAM + |
|
61 (encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET)); |
|
62 } |
|
63 |
|
64 /** |
|
65 * Constructs a new {@link UrlEncodedFormEntity} with the list |
|
66 * of parameters with the default encoding of {@link HTTP#DEFAULT_CONTENT_CHARSET} |
|
67 * |
|
68 * @param parameters list of name/value pairs |
|
69 * @throws UnsupportedEncodingException if the default encoding isn't supported |
|
70 */ |
|
71 public UrlEncodedFormEntity ( |
|
72 final List <? extends NameValuePair> parameters) throws UnsupportedEncodingException { |
|
73 this(parameters, HTTP.DEFAULT_CONTENT_CHARSET); |
|
74 } |
|
75 |
|
76 } |