Why do you have to call URLConnection#getInputStream to be able to write out to URLConnection#getOutputStream?

后端 未结 6 1748
情书的邮戳
情书的邮戳 2020-11-27 05:28

I\'m trying to write out to URLConnection#getOutputStream, however, no data is actually sent until I call URLConnection#getInputStream. Even if I set URLConnnection#doInput

6条回答
  •  长情又很酷
    2020-11-27 06:00

    Calling getInputStream() signals that the client is finished sending it's request, and is ready to receive the response (per HTTP spec). It seems that the URLConnection class has this notion built into it, and must be flush()ing the output stream when the input stream is asked for.

    As the other responder noted, you should be able to call flush() yourself to trigger the write.

提交回复
热议问题