I have a problem with HTPSUR connections which I can not solve. Basically, I'm sending some information to a server and if some of that data is wrong, then the server sends me 500 response codes. However, it sends a message to me in the response that what data was wrong. The problem is that the message is always empty when the message is read. I think this is because a file incomplete exception always throws before the stream can be read. Am i right I tried to read the error report but it is always empty here's a snippet:
conn = (HttpsURL connection) connectURL.openConnection (); Conn.setDoOutput (true); Conn.setConnectTimeout (30000); Conn.setReadTimeout (30000); Conn.setRequestMethod ("post"); Conn.setRequestProperty ("content-length", integer.stosting (outstring.getbits.) length)); DataOutputStream wr = New DataOutputStream (conn .getOutputStream ()); Wr.write (outString.getBytes ()); Wr.flush (); Wr.close (); If (conn.getResponseCode> 400 {string response = getErrorResponse (conn); public string getErrorResponse (HttpsURLConnection conn) {Log.i (in TAG, "getResponse"); InputStream = Faucet; Try {// is = conn. GetInputStream (); is = scoop the reply from conn.getErrorStream (); // server int; stringbuffer sb = new stringbuffer (); while ((ch = is.read ())! = -1) {sb. Attachment (four) f}} // System.out.printLN (SBSTosting ()); Return sb.toString (); // Return Conference ID;} Catch (Exception e) {e.printStackTrace ();} }
just this To follow up, here's how I solve it:
Public Static String Mill Response (HTPS URL Connection Connection) {Log.i (TAG, "getResponse" InputStream = Faucet; Try {if (conn.getResponseCode ()> = 400) {is = conn.getErrorStream ();} and {is = conn.getInputStream ();} ... read the stream ...} It seems that by making such a call, an error stream was generated with the message. Thanks for the suggestions!
Comments
Post a Comment