I have a java code that sends a web service request to the interfaces. Now for one of the interface I a getting the following error
java.lang.IllegalArgumentException: Illegal character(s) in message header field: http://10.11.22.33:8088/platform-core/smsGateMgw
at sun.net.www.protocol.http.HttpURLConnection.checkMessageHeader(HttpURLConnection.java:522)
at sun.net.www.protocol.http.HttpURLConnection.isExternalMessageHeaderAllowed(HttpURLConnection.java:492)
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:3057)
at com.in.ci.fioutbound.custom.SmsSender.sendSms(SmsSender1.java:255)
at com.in.ci.fioutbound.custom.SmsSender.executeOutboundRequest(SmsSender1.java:104)
I guess this is because of the "-" in the URL but not sure. Can someone please let me know how to encode the path of a URL or is there some other way to handle this. This is how my java code looks like now
URL smsServiceUrl = new URL(smsService);
URLConnection conn = smsServiceUrl.openConnection();
HttpURLConnection httpconn = (HttpURLConnection)conn;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] buffer = new byte[reqXml.length()];
buffer = reqXml.getBytes();
bout.write(buffer);
byte[] b = bout.toByteArray();
httpconn.setRequestProperty("Content-Length", String.valueOf(b.length));
httpconn.setRequestProperty("Content-Type", "text/xml;charset=utf-8");
httpconn.setRequestProperty(smsService, smsService);
httpconn.setRequestMethod("POST");
httpconn.setDoOutput(true);
httpconn.setDoOutput(true);
OutputStream out = httpconn.getOutputStream();
out.write(b);
InputStreamReader isr = new InputStreamReader(httpconn.getInputStream());
BufferedReader in = new BufferedReader(isr);
while ((responseString = in.readLine()) != null) {
outputString = outputString + responseString;
}
Also, the same code works fine in another server with the same URL. The only difference is of java 1.7 and 1.8 between the two servers. So is this a new functionality in java 1.8?