Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
HttpURLConnection to Windows vs Lunux problems
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="David G, post: 550356"] Hello, I have run across a really weird situation with the HttpURLConnection. I always seem to get the following error when connecting (via HttpURLConnection) to a lunux tomcat servlet engine: java.io.IOException: Server returned HTTP response code: 500 for URL: [URL]http://venus/david/utils/formTester.jsp?url=testurl&[/URL] However, when I make a connection to the exact same page on a windows tomcat it works. This is what I'm seeing. When ever I request a static page from tomcat (on linux), it works fine, but if I request a jsp it breaks with the 500 error above. For example: venus is a linux server and davidlg is my development windows 2000 pt.doGet("[URL]http://venus/index.html[/URL]"); // returns the html page pt.doGet("[URL]http://venus:8080/david/utils/password.jsp[/URL]"); // returns error 500 pt.doGet("[URL]http://venus:8080/david/utils/formTester.jsp?url=testurl[/URL]"); // returns error 500 pt.doGet("[URL]http://davidlg:8084/index.html[/URL]"); // returns html pt.doGet("[URL]http://davidlg:8084/apps/utils/password.jsp[/URL]"); // returns generated web page (simple page that looks for cgi parm and prints it) pt.doGet("[URL]http://davidlg:8084/apps/utils/formTester.jsp?url=testurl[/URL]");// returns generated web page (another simple page that prints a form with a cgi parm in it) Anybody have any ideas? This is driving me nuts... Here is my code that makes the connection: public String doGet(String urlString, Hashtable parms) throws ProtocolException, IOException, UnsupportedEncodingException { String name; String value; // make sure there is a ? between the page and parms. Enumeration e = parms.keys(); if (urlString.indexOf("?") < 0) { urlString += "?"; } else if (urlString.indexOf("?") != urlString.length() - 1) { urlString += "&"; } boolean useDepracated = false; log("java.version:" + System.getProperty("java.version")); useDepracated = (System.getProperty("java.version").indexOf("1.2")) == 0; if (useDepracated) { log( "Found earlier version of java (1.2.2), using the" + " depricated version of url encode:"); } while (e.hasMoreElements()) { name = (String)e.nextElement(); value = (String)parms.get(name); // encode the value: if (useDepracated) { value = URLEncoder.encode(value); } else { value = URLEncoder.encode(value, "UTF-8"); } urlString += name + "=" + value + "&"; log(name + "=" + value + "&"); } log("Sending the following to " + urlString); URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setRequestMethod("GET"); conn.setDoOutput(true); PrintWriter out = new PrintWriter(conn.getOutputStream()); out.println(); out.flush(); out.close(); // read the response: //conn.connect(); conn.getResponseMessage(); // OK, Forbidden, etc conn.getResponseCode(); // 200, 404, etc // this is where it throws the 500 error. BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuffer response = new StringBuffer(); String line; while ((line = in.readLine()) != null) { log(line); response.append(line); } in.close(); return response.toString(); } Thanks for any suggestions you have to offer. -David [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
HttpURLConnection to Windows vs Lunux problems
Top