| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -126,5 +126,11 @@ | |||
| 126 | 126 | <version>4.12</version> | |
| 127 | 127 | <scope>test</scope> | |
| 128 | 128 | </dependency> | |
| 129 | + <dependency> | ||
| 130 | + <groupId>commons-io</groupId> | ||
| 131 | + <artifactId>commons-io</artifactId> | ||
| 132 | + <version>2.4</version> | ||
| 133 | + <scope>test</scope> | ||
| 134 | + </dependency> | ||
| 129 | 135 | </dependencies> | |
| 130 | 136 | </project> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,7 @@ a copy of this software and associated documentation files (the | |||
| 29 | 29 | import java.util.List; | |
| 30 | 30 | import java.util.Map; | |
| 31 | 31 | import java.util.Map.Entry; | |
| 32 | + import java.util.TreeMap; | ||
| 32 | 33 | ||
| 33 | 34 | import org.apache.http.NameValuePair; | |
| 34 | 35 | import org.apache.http.message.BasicNameValuePair; | |
@@ -38,7 +39,8 @@ public class MapUtil { | |||
| 38 | 39 | public static List<NameValuePair> getList(Map<String, List<Object>> parameters) { | |
| 39 | 40 | List<NameValuePair> result = new ArrayList<NameValuePair>(); | |
| 40 | 41 | if (parameters != null) { | |
| 41 | - for(Entry<String, List<Object>> entry : parameters.entrySet()) { | ||
| 42 | + TreeMap<String, List<Object>> sortedParameters = new TreeMap<String, List<Object>>(parameters); | ||
| 43 | + for(Entry<String, List<Object>> entry : sortedParameters.entrySet()) { | ||
| 42 | 44 | List<Object> entryValue = entry.getValue(); | |
| 43 | 45 | if (entryValue != null) { | |
| 44 | 46 | for(Object cur : entryValue) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ a copy of this software and associated documentation files (the | |||
| 33 | 33 | ||
| 34 | 34 | import java.io.File; | |
| 35 | 35 | import java.io.IOException; | |
| 36 | + import java.io.InputStream; | ||
| 36 | 37 | import java.net.InetAddress; | |
| 37 | 38 | import java.net.URISyntaxException; | |
| 38 | 39 | import java.net.UnknownHostException; | |
@@ -45,6 +46,8 @@ a copy of this software and associated documentation files (the | |||
| 45 | 46 | import java.util.concurrent.TimeUnit; | |
| 46 | 47 | import java.util.concurrent.atomic.AtomicInteger; | |
| 47 | 48 | ||
| 49 | + import com.mashape.unirest.request.HttpRequest; | ||
| 50 | + import org.apache.commons.io.IOUtils; | ||
| 48 | 51 | import org.apache.http.impl.client.HttpClientBuilder; | |
| 49 | 52 | import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; | |
| 50 | 53 | import org.json.JSONArray; | |
@@ -685,5 +688,18 @@ public void setTimeoutsAndCustomClient() { | |||
| 685 | 688 | // Ok | |
| 686 | 689 | } | |
| 687 | 690 | } | |
| 688 | - | ||
| 691 | + | ||
| 692 | + @Test | ||
| 693 | + public void testPostProvidesSortedParams() throws IOException { | ||
| 694 | + // Verify that fields are encoded into the body in sorted order. | ||
| 695 | + HttpRequest httpRequest = Unirest.post("test") | ||
| 696 | + .field("z", "Z") | ||
| 697 | + .field("y", "Y") | ||
| 698 | + .field("x", "X") | ||
| 699 | + .getHttpRequest(); | ||
| 700 | + | ||
| 701 | + InputStream content = httpRequest.getBody().getEntity().getContent(); | ||
| 702 | + String body = IOUtils.toString(content, "UTF-8"); | ||
| 703 | + assertEquals("x=X&y=Y&z=Z", body); | ||
| 704 | + } | ||
| 689 | 705 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments