Skip to content

Instantly share code, notes, and snippets.

@bitfishxyz
Created March 26, 2019 02:46
Show Gist options
  • Save bitfishxyz/58a072854e0cf4752eb910940114a955 to your computer and use it in GitHub Desktop.
Save bitfishxyz/58a072854e0cf4752eb910940114a955 to your computer and use it in GitHub Desktop.
Parse QueryString in Java with apache URLEncodedUtils
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import java.net.URI;
import java.util.List;
public class B {
public static void main(String[] args) throws Exception {
String url = "http://www.example.com/something.html" +
"?one=1&two=2&three=3&three=3a";
List<NameValuePair> params = URLEncodedUtils.parse(
new URI(url), "UTF-8");
for (NameValuePair param : params) {
System.out.println(param.getName() + " : " + param.getValue());
}
}
}
// one : 1
// two : 2
// three : 3
// three : 3a
@bitfishxyz
Copy link
Author

Maven:

<dependency>
     <groupId>org.apache.httpcomponents</groupId>
     <artifactId>httpclient</artifactId>
     <version>4.5</version>
</dependency>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment