I have been dealing with a problem for some time and would really appreciate it if somebody can give me some pointers.
I basically have to perform an ajax call to an aspx page on another server. In IE8 this does not work due to cross-domain problems. Some people suggested I tried jquery's datatype "jsonp" and that doing so is going to allow cross-domain communication in IE8 but it failed.
So, in order to solve that problem, I have a browser detection routine in my code that checks if it is IE8. If it is IE8 what I do is that I do an ajax call to an interim jsp page.
What the interim jsp page is supposed to do, is take those parameters and basically post them to an aspx page.
Regarding this this is the code I am using:
<%
// get the parameters
String fileName = request.getParameter("fileName");
String param02 = request.getParameter("param02");
String param03 = request.getParameter("param03");
String param05 = request.getParameter("param05");
String param08 = request.getParameter("param08");
String param11 = request.getParameter("param11");
java.net.URL url;
java.net.HttpURLConnection connection = null;
try {
String urlParameters = "fileName="+ fileName+"¶m02="+ param02+"¶m03="+ param03+"¶m05="+ param05+"¶m08="+ param08+"¶m11="+ param11;
String encodedurl = java.net.URLEncoder.encode(urlParameters);
out.println(encodedurl);
//Create connection
url = new java.net.URL(
"https://somepage.aspx");
connection = (java.net.HttpURLConnection) url
.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
////connection.setRequestProperty("Content-Type","text/xml; charset=utf-8");
connection.setRequestProperty("Content-Length", "" +
Integer.toString(encodedurl.getBytes().length));
connection.setRequestProperty("Content-Language", "en-US");
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
//Send request
DataOutputStream wr = new DataOutputStream (
connection.getOutputStream ());
wr.writeBytes (encodedurl);
wr.flush ();
wr.close ();
out.println(connection.getResponseCode());
//Get Response
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer responseBuffer = new StringBuffer();
while((line = rd.readLine()) != null) {
responseBuffer.append(line);
responseBuffer.append('\r');
}
rd.close();
out.println("\n\nRESPONSE\n\n" +responseBuffer.toString());
out.println(connection.getErrorStream());
} catch (Exception e) {
e.printStackTrace();
out.println("Exception :(+ " +e);
} finally {
if(connection != null) {
connection.disconnect();
}
}
%>
The code results with the following error:
java.io.IOException: Server returned HTTP response code: 500
When in chrome, the normal ajax call is performed and that works - nothing similar to this error code.
Can anybody please help out.