我正在HttpURLConnection类从我的应用程序做一些网络活动。所以我想知道HttpURLConnection如何在内部工作。我经历了课程,发现连接()方法定义为URLConnection中的摘要。Android HttpURLConnection如何工作?
但我无法找到连接()方法的定义。所以我很好奇,HttpURLConnection如何连接到服务器。
mycode的:
URL url = new URL("https://example.com");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Accept-Encoding", "identity");
connection.setRequestProperty("Authorization", basicAuth);
connection.setRequestProperty("Connection", "keep-alive");
connection.setRequestProperty("Content-type", "");
connection.setRequestProperty("User-Agent", "LibHttp/1.3.8");
connection.setRequestMethod("POST");
connection.connect(); // how it connects //
请建议我一些解决方案。
也许这可能会帮助你[Java URLConnection - 我什么时候需要使用connect()方法?](http://stackoverflow.com/questions/16122999/java-urlconnection-when-do-i-need-使用该连接方法) – Isabelle