java.lang.IllegalStateException: Write attempted after request finished
对于http连接,仅能进行一次读写,并且要先写入完毕才能打开输入流进行读操作
int responseCode = conn.getResponseCode();
DataOutputStream dos = conn.openDataOutputStream();
dos.writeUTF(name);
dos.writeUTF(PassWrod);
dos.flush();
这段代码中
把 int responseCode = conn.getResponseCode();
放在后面,即先写完再请求返回数据
=============
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 receiving data. It/'a a question answer gave. After the answer, you cannot state another question without a reconnect (or use http 1.1, but that should 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