我很好奇 HttpURLConnection 如何获取连接的输入流。查了父抽象类URLConnection的实现,找到了方法
/**
* Returns an {@code InputStream} for reading data from the resource pointed by
* this {@code URLConnection}. It throws an UnknownServiceException by
* default. This method must be overridden by its subclasses.
*
* @return the InputStream to read data from.
* @throws IOException
* if no InputStream could be created.
*/
public InputStream getInputStream() throws IOException {
throw new UnknownServiceException("Does not support writing to the input stream");
}
扩展 URLConnection 的 HttpURLConnection 不会覆盖此方法。那么想知道如何获得输入流引用?
与此相关的东西.... http 请求到底是什么时候从客户端发送到服务器的?是在您调用 getInputStream() 时吗?或者一旦调用 openConnection() ?
提前感谢 AK