Getting response of Server after sending post upload data

Butehfly

New Member
I need to get the answer of a request to the server.The code is listet after this post.I modified the code as following:\[code\] try{ byte[] inray = payload.getBytes(); HttpURLConnection connection = null; DataOutputStream outputStream = null; String lineEnd = "\r\n"; String twoHyphens = "--"; String boundary = "*****"; byte[] buffer; URL url = new URL(urlServer); connection = (HttpURLConnection) url.openConnection(); // Allow Inputs & Outputs connection.setDoInput(true); connection.setDoOutput(true); connection.setUseCaches(false); // Enable POST method connection.setRequestMethod("POST"); connection.setRequestProperty("Connection", "Keep-Alive"); connection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary); outputStream = new DataOutputStream( connection.getOutputStream() ); outputStream.writeBytes(twoHyphens + boundary + lineEnd); outputStream.writeBytes("Content-Length: "+inray.length+"; Content-Disposition: form-data; name=\"uploadedfile\";filename=\"spectware.xml\"" + lineEnd); outputStream.writeBytes(lineEnd); int bytelength = 1024*16; int num = (int)(inray.length /bytelength); int min = 0; int max = 0; api.debug("com.api.tools.serverCommunication","Length: "+inray.length,"info"); for(int i=0; i<num;i++){ api.debug("com.api.tools.serverCommunication","Run: "+i,"info"); buffer = new byte[bytelength]; min = i*bytelength; max = i*bytelength; max += bytelength; api.debug("com.api.tools.serverCommunication","min: "+min,"info"); api.debug("com.api.tools.serverCommunication","max: "+max,"info"); for(int j = 0;j<bytelength; j++){ buffer[j] = inray[(min + j)]; } outputStream.write(buffer,0,bytelength); } api.debug("com.api.tools.serverCommunication","Last: "+(inray.length-min)+" - "+((inray.length-min)>0) ,"info"); if((inray.length-min)>0){ api.debug("com.api.tools.serverCommunication","min: "+min,"info"); api.debug("com.api.tools.serverCommunication","max: "+inray.length,"info"); buffer = new byte[(inray.length-min)]; api.debug("com.api.tools.serverCommunication","Size of last: "+buffer.length,"info"); for(int i=0;i<buffer.length;i++){ buffer = inray[(i+min)]; } outputStream.write(buffer,0,buffer.length); } outputStream.writeBytes(lineEnd); outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); api.debug("com.api.tools.serverCommunication","Output"+connection.getResponseCode(),"info"); api.debug("com.api.tools.serverCommunication","Output"+connection.getResponseMessage(),"info"); api.debug("com.api.tools.serverCommunication","Output"+connection.getContent().toString(),"info"); answer = new parseAnswer(connection.getResponseMessage()); answer.setResponsecode(connection.getResponseCode()); outputStream.flush(); outputStream.close(); } catch (Exception ex) { api.debug("com.api.tools.serverCommunication","Server Exception "+ex.getMessage(),"info"); api.debug("com.api.tools.serverCommunication","Server Exception "+ex.getCause(),"info"); StackTraceElement[] d = ex.getStackTrace(); for(int i=0; i<d.length; i++) api.debug("com.api.tools.serverCommunication","Trace: "+d.getClassName()+"-"+d.getLineNumber()+"-"+d.getMethodName()+"-"+d.toString(),"info"); }\[/code\]so far the request is sent to the server.But I need the response from the Server.The Server answers with an xml document that tells the client, if the request was successfull or not. Also gives details on errors etc.So how do I get this content?
 
Back
Top