Cannot write output after reading input.

I

igoR Buttler

Hi everybody,

I'm trying to post a file to my server but am having quite some issues. I
open the HttpURLConnection and then try to get the outputstream. When I do
this I get a
"java.net.ProtocolException: Cannot write output after reading input.". In
my understanding this error occurs when you try to write to the outputstream
when you have already read from the inputstream but here I am only trying to
get the outputstream without writing to anyhing. My code is attached below.
Any suggestions?



public void openConnection()
{
try
{
URL pisces = new URL(url);
urlConnection = (HttpURLConnection)pisces.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setAllowUserInteraction(false);
urlConnection.setUseCaches(false);
urlConnection.setRequestMethod("POST");
}
catch (Exception e)
{
e.printStackTrace(System.out);
}
}

private void sendJar()
{
openConnection();
BufferedReader in = null;
DataOutputStream out = null;

try
{
out = new DataOutputStream(urlConnection.getOutputStream());
...Excepeion is thrown here
 
A

ak

I'm trying to post a file to my server but am having quite some issues. I
open the HttpURLConnection and then try to get the outputstream. When I do
this I get a
"java.net.ProtocolException: Cannot write output after reading input.". In
my understanding this error occurs when you try to write to the outputstream
when you have already read from the inputstream but here I am only trying to
get the outputstream without writing to anyhing. My code is attached below.
Any suggestions?



public void openConnection()
{
try
{
URL pisces = new URL(url);
urlConnection = (HttpURLConnection)pisces.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setAllowUserInteraction(false);
urlConnection.setUseCaches(false);
urlConnection.setRequestMethod("POST");
}
catch (Exception e)
{
e.printStackTrace(System.out);
}
}

private void sendJar()
{
openConnection();
BufferedReader in = null;
DataOutputStream out = null;

try
{
out = new DataOutputStream(urlConnection.getOutputStream());
...Excepeion is thrown here

try this:
urlConnection.setAllowUserInteraction(true);

____________

http://reader.imagero.com the best java image reader.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top