Server refuses encoded URL from Java application
I'm trying to send an encoded URL using a Java application via HttpURLConnection. The server accepts the httpRequest just fine when there are no percent encoded values (ex.http://10.132.1.1:80/xx?x=in&xt=&s=&d=&de=&a=&p=&o=&MSISDN=639991234567). But once the percent encoded values are added to the URL as the value of a request parameter(ex.x=in&xt=&s=&d=L%3A%0CM%8B%CEh%2F&de=L%3A%0CM%8B%CEh%2F&de=&a=&p=&o=&MSISDN=639991234567), the server rejects it. I tried sending the latter url using a web browser, and the server accepted it. Here's the code im using:
try {
String data = null;
if(argv.length > 0 && argv[0]!=null)
{
data = argv[0];
}
else
{
data = "x=ba&xt=cd&s=CRIS&d=&de=&a=&p=&o=&MSISDN=639990001111";
}
String hostIP = "http://Put hostIP:port here";
URL url = new URL(hostIP + "?" + data);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty ("Content-Type","application/octet-stream");
//conn.setUseCaches (false);
//conn.setDefaultUseCaches (false);
//conn.setRequestMethod("POST");
//conn.setDoOutput(true);
//conn.setRequestProperty("Content-Type","UTF-8");
conn.connect();
if(conn.getErrorStream() != null)
{
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
String line;
while ((line = rd.readLine()) != null) {
// Process line...
System.out.println(line);
}
//wr.close();
rd.close();
}
//OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
//wr.write(data);
//wr.flush();
// Get the response
System.out.println("Response code:" + conn.getResponseCode());
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
// Process line...
System.out.println(line);
}
//wr.close();
rd.close();
} catch (Exception e) {
System.out.println(e);
}
Can you please help me? Thank you very much.

