Hi all,

I'm in the middle of developing my first android application and have
finally hit a significant roadblock that I can't seem to figure a way
around.

The application involves HTTPS posting from an activity within the app
to my test server. While I've worked around accepting the self-signed
certificate, the behavior of the post and response has been
problematic and non-standard and so I'm wondering if this issue is
android related and what some possible solutions might be.

Essentially this transaction is completed on a click. On the click I
create and connect a HttpsURLConnection to the server, setting
DoOutput and DoInput to true. I get the connection output stream and
wrap it in a  BufferedOutputStream. I write the transaction to the
BuffStream, flush and close it.

Then I handle the response. If the response is HTTP_OK, I get and wrap
the connection input stream in a BufferedInputStream. I then take the
input and put it into a byte array to be handled by the app and close
the input stream.

Now this all seems straight forward but when tested doesn't work
properly. From the activity, the process is always successful on the
first try, but then from the same activity if I wait a few seconds
then click again, the same process will fail claiming a
java.io.IOException(stream is closed), and then if I wait a few more
seconds and try again it will work and this pattern continues on. To
make things even more confusing, if I execute all of the clicks in
rapid succession they will all work. It only complains if I wait in
between transactions. I've come to think that the problem has
something to do with Android HTTPS as when I try just a simple HTTP
post, everything works fine. I also don't think it has anything to do
with my custom certificate accepting as when I removed that and tried
HTTPS posting to a trusted well known certificate, the problem still
occurred.

I'm leaning towards the thought that this has something to do with
setting up and tearing down HTTPS connections in android, but as I do
this all in an onClick event I'm not sure why I'm experiencing
problems half the time. I'm also inclined to think its the inputStream
that is having issues as the server seems to recieve the transactions.

Anyone with any ideas as to what could be going wrong, or anyone who
can outline how they went about setting up an HTTPS post on click
would be greatly appreciated!

Thanks so much for your time and consideration.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to