我使用如下方式想要获取某个网页的数据:
URL url = new URL(str);
httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setConnectTimeout(15000);
httpURLConnection.setReadTimeout(15000);
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
传入的url为http://www.baidu.com或者http://www.csdn.net,使用如下方法后去输入流及返回码:
InputStream input = connection.getInputStream();
int code = connection.getResponseCode();
但是执行的结果却是:
code: 301
respose: <html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>openresty</center>
</body>
</html>