0
我在通过代理在浏览器上显示网站时遇到问题。我从Internet选项手动将我的代理设置为127.0.0.1:80。在代码中,当我连接到网站时,我可以获取html代码并将其打印在我的java控制台上。但是,当我将html代码发送到我的浏览器时,我可以看到它连接到网站并显示“Welcome to Facebook”这样的标题。但我看不到内容。有时我只看到文字而不是图像或其他东西。显示网页内容存在问题。我无法弄清楚。也许你可以帮助我。另外我认为我无法获得UTF-8格式的内容。谢谢。通过代理服务器通过java连接到网站
try {
URL url = new URL("" + req.url);
URLConnection urlConnection = url.openConnection();
DataInputStream dis = new DataInputStream(urlConnection.getInputStream());
String inputLine;
while ((inputLine = dis.readLine()) != null) {
// System.out.println(inputLine);
out.writeUTF(inputLine);
}
dis.close();
} catch (MalformedURLException me) {
System.out.println("MalformedURLException: " + me);
} catch (IOException ioe) {
System.out.println("IOException: " + ioe);
}
这是我如何发送线路浏览器。
private DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream());
我仍然无法连接。 –
任何错误或异常? –
它没有给出任何错误,但当我做到这一点时也没有任何改变。我通过代理向writeUTF(inputLine)发送我从网站上读取的行。我打开一个套接字将这些行发送到我的浏览器。所以我不明白为什么我仍然不能显示这些网页 –