Chase Casanova | I am trying to write a java class that will submit an XML request to the EMServiceServlet. What I have now returns a 500 Internal Server Error, just like if I were to visit the servlet with a web browser. So I think my problem is with my headers, but I can't be sure. Does anyone see anything wrong with my code? import java.io.*; import java.net.*; public class EMLoginLogout { public static String emLogin(String userid, String phoneName, String appID, String appPasswd) { // Build XML String String XMLString = new String(); XMLString = "<request>"; XMLString += "<appInfo>"; XMLString += "<appID>" + appID + "</appID>"; XMLString += "<appCertificate>" + appPasswd + "</appCertificate>"; XMLString += "</appInfo>"; XMLString += "<login>"; XMLString += "<deviceName>" + phoneName + "</deviceName>"; XMLString += "<userID>" + userid + "</userID>"; XMLString += "<exclusiveDuration>"; XMLString += "<time>60</time>"; XMLString += "</exclusiveDuration>"; XMLString += "</login>"; XMLString += "</request>"; try { // Make connection URL url = new URL("http://X.X.X.X:8080/emservice/EMServiceServlet"); URLConnection urlConnection = url.openConnection(); urlConnection.setRequestProperty("Content-Type", "text/xml; charset=\"utf-8\""); urlConnection.setDoInput(true); urlConnection.setDoOutput(true); urlConnection.connect(); OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream(),"UTF8"); // Write XML string to request body out.write(XMLString); out.flush(); // Read the response BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String line = null; while ((line = in.readLine()) != null) { //System.out.println(line); line += in.readLine(); } out.close(); in.close(); return line; } catch (UnknownHostException e) { System.err.println("Error connecting to host: " + e.getMessage()); return "-2"; } catch (IOException ioe) { System.err.println("Error sending/receiving from server: " + ioe.getMessage()); // close the socket } catch (Exception ea) { System.err.println("Unknown exception " + ea.getMessage()); return "-3"; } return XMLString; } } Thanks, -C |
| Please sign in to flag this as inappropriate. |