Commit 66d4ed7b by Adi Amir

support query parameter without name=

parent 06c5b9ca
group 'com.ipgallery.common' group 'com.ipgallery.common'
version '1.2.6' version '1.3.1'
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
......
...@@ -99,30 +99,40 @@ public class SimpleHttpRequest { ...@@ -99,30 +99,40 @@ public class SimpleHttpRequest {
this.queryString = ""; this.queryString = "";
} }
public void addQueryStringParam(String name, String value) { public void addQueryStringParam(String name, String value) {
String escName = pes.escape(name);
// escape name
String escName = null;
if (name != null && name.isEmpty() == false)
escName = pes.escape(name);
// escape value
String escValue = pes.escape(value); String escValue = pes.escape(value);
// add to query string
if (!queryString.equals("")) if (!queryString.equals(""))
queryString += "&"; queryString += "&";
if (escName != null)
queryString += escName + "=" + escValue; queryString += escName + "=" + escValue;
else
queryString += escValue;
} }
private String EscapeQueryString(String queryString) { private String EscapeQueryString(String queryString) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String[] paramTokens = queryString.split("&"); String[] params = queryString.split("&");
if (paramTokens != null) { if (params != null) {
for (String param: paramTokens) { for (String param: params) {
// split the param into name and value // split the param into name and value
String[] fieldTokens = new String[2]; //String[] fieldTokens = new String[2];
int equalPos = param.indexOf('='); int equalPos = param.indexOf('=');
if (equalPos > 0) { if (equalPos > 0) {
fieldTokens[0] = param.substring(0, equalPos); String name = param.substring(0, equalPos);
fieldTokens[1] = param.substring(equalPos + 1); String value = param.substring(equalPos + 1);
if (fieldTokens != null && fieldTokens.length == 2) { String escapedParam = pes.escape(name) + "=" + pes.escape(value);
String field = pes.escape(fieldTokens[0]) + "=" + pes.escape(fieldTokens[1]);
if (sb.length() > 0) if (sb.length() > 0)
sb.append("&"); sb.append("&");
sb.append(field); sb.append(escapedParam);
}
} }
else else
sb.append(pes.escape(param)); sb.append(pes.escape(param));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment