Cannot write output after reading input.

  • Follow


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




0
Reply nospam2529 (2) 1/6/2004 12:29:19 AM

> 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.


0
Reply spam381 (201) 1/6/2004 5:54:03 AM


It's probably this problem:

http://www.javaworld.com/javaworld/jw-03-2001/jw-0323-traps.html

Hope this helps.

- sarge
0
Reply sarge_chris (23) 1/6/2004 11:39:57 AM

2 Replies
145 Views

(page loaded in 0.251 seconds)

Similiar Articles:













7/28/2012 6:41:51 AM


Reply: