Skip to content

Commit 06a0148

Browse files
committed
HttpClient URI space to %20, not +
1 parent aa42c8e commit 06a0148

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

sources/net.sf.j2s.java.core/src/javajs/http/SimpleHttpClient.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.FileInputStream;
66
import java.io.IOException;
77
import java.io.InputStream;
8+
import java.io.UnsupportedEncodingException;
89
import java.net.HttpURLConnection;
910
import java.net.MalformedURLException;
1011
import java.net.URI;
@@ -308,7 +309,7 @@ private Response fulfillGet(Response r) throws IOException {
308309
htGetParams.put(fd.getName(), fd.getData().toString());
309310
}
310311
for (Entry<String, String> e : htGetParams.entrySet()) {
311-
data += e.getKey() + "=" + URLEncoder.encode(e.getValue(), "UTF-8");
312+
data += e.getKey() + "=" + encodeURI(e.getValue());
312313
}
313314
}
314315
if (data.length() > 0) {
@@ -319,6 +320,16 @@ private Response fulfillGet(Response r) throws IOException {
319320
return r.getResponse(getConnection(url), this);
320321
}
321322

323+
private String encodeURI(String value) {
324+
try {
325+
return URLEncoder.encode(value.replace(' ', '\0'), "UTF-8").replaceAll("%00", "%20");
326+
} catch (UnsupportedEncodingException e) {
327+
// impossible
328+
}
329+
330+
return null;
331+
}
332+
322333
private Response fulfillPost(Response r) throws IOException {
323334
HttpURLConnection conn = getConnection(uri.toURL());
324335
sendFormData(conn, formData);

0 commit comments

Comments
 (0)