Commit 66d4ed7b by Adi Amir

support query parameter without name=

parent 06c5b9ca
group 'com.ipgallery.common'
version '1.2.6'
version '1.3.1'
apply plugin: 'java'
apply plugin: 'maven-publish'
......
......@@ -99,30 +99,40 @@ public class SimpleHttpRequest {
this.queryString = "";
}
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);
// add to query string
if (!queryString.equals(""))
queryString += "&";
queryString += escName + "=" + escValue;
if (escName != null)
queryString += escName + "=" + escValue;
else
queryString += escValue;
}
private String EscapeQueryString(String queryString) {
StringBuilder sb = new StringBuilder();
String[] paramTokens = queryString.split("&");
if (paramTokens != null) {
for (String param: paramTokens) {
String[] params = queryString.split("&");
if (params != null) {
for (String param: params) {
// split the param into name and value
String[] fieldTokens = new String[2];
//String[] fieldTokens = new String[2];
int equalPos = param.indexOf('=');
if (equalPos > 0) {
fieldTokens[0] = param.substring(0, equalPos);
fieldTokens[1] = param.substring(equalPos + 1);
if (fieldTokens != null && fieldTokens.length == 2) {
String field = pes.escape(fieldTokens[0]) + "=" + pes.escape(fieldTokens[1]);
if (sb.length() > 0)
sb.append("&");
sb.append(field);
}
String name = param.substring(0, equalPos);
String value = param.substring(equalPos + 1);
String escapedParam = pes.escape(name) + "=" + pes.escape(value);
if (sb.length() > 0)
sb.append("&");
sb.append(escapedParam);
}
else
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