我按照教程来却发现总是报错;
代码如下
private String url; //请求的地址
public httpThread(String url) {
this.url = url;
}
public String doGet() {
URL httpUrl = null;
try {
httpUrl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
HttpURLConnection httpURLConnection;
httpURLConnection = (HttpURLConnection) new httpUrl.openConnection();
try {
httpURLConnection.setRequestMethod("GET"); //请求get方法
} catch (ProtocolException e) {
e.printStackTrace();
}
httpURLConnection.setReadTimeout(5000);
//接受返回来的数据
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
} catch (IOException e) {
e.printStackTrace();
}
String str;
StringBuffer sb = new StringBuffer();
try {
while ((str = reader.readLine()) != null) {
sb.append(str);
}
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
![图片描述][2]
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
请问 这是什么教程?使用浏览器看看请求是否管用 有可能作者编写时可以访问但是后来不能了
这就是个方法你把new去掉啊