這是我的代碼URL連接InputStream和OutputStream對象
URL url = new URL("http://172.16.32.160:8080/epramaan/loginotp");
URLConnection connection1 = url.openConnection();
connection1.setDoOutput(true);
ObjectOutputStream out=new ObjectOutputStream(connection1.getOutputStream());
out.writeObject(send);
out.flush();
out.close();
ObjectInputStream in = new ObjectInputStream(connection1.getInputStream());
String output=(String)in.readObject();
in.close();
//Rest of the code
一旦OutputStream以便向流寫入數據時,將對象的InputStream停止執行,直到接收到響應?
你應該發送任何數據,保證你會得到你 – 2012-03-13 10:51:51
您使用out.writeObject發送數據之前意味着服務器所需要的一切()我應該初始化對象的inputStream之前打開輸入流?你能否詳細說明 – suraj 2012-03-13 10:57:39
@MichaelLaffargue - 其實我不認爲這是必要的。 HTTP 1.1 RFC說明了這一點 - *「在接收並解釋請求消息後,服務器用HTTP響應消息進行響應。」*。 (第6節)。操作詞是「之後」。在仍然讀取請求的同時開始發送響應的服務器將違反規範。因此,在輸出流關閉之前不需要打開輸入流。 – 2012-03-13 11:37:46