Java. Lang. illegalstateexception: Write attempted after request finished

Source: Internet
Author: User

Java. Lang. illegalstateexception: Write attempted after request finished
For HTTP connections, only one read/write can be performed, and the input stream can be opened for read operations only after the write is completed.

 

 

Int responsecode = conn. getresponsecode ();

Dataoutputstream dos = conn. opendataoutputstream ();
Dos. writeutf (name );
Dos. writeutf (passwrod );
Dos. Flush ();
This sectionCodeMedium
Set int responsecode = conn. getresponsecode ();
Put it at the end, that is, write and then request to return data

 

 

==================

1. How about actually closing a connection before opening a new one?
2. IT/'s HTTP, not a socket, you can/'t keep sending and processing data. IT/'a question answer gave. after the answer, you cannot state another question without a reconnect (or use HTTP 1.1, but that shoshould be transparantly ). even though you set the keep-alive request propery
3. A post works in this oder:

-Init your headers
-Open output steam
-Write Data
-Check response code
-Open input stream
-Read data
-Close all

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.