Java-在Web浏览器中显示HttpResponse的内容
所以我做了一个小程序,它向一个网站发送一个post方法,然后打印出响应,我能在网络浏览器中显示响应吗Java-在Web浏览器中显示HttpResponse的内容,java,http,post,browser,apache-commons-httpclient,Java,Http,Post,Browser,Apache Commons Httpclient,所以我做了一个小程序,它向一个网站发送一个post方法,然后打印出响应,我能在网络浏览器中显示响应吗 HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
if (line.startsWith("Auth=")) {
String key = line.substring(5);
// Do something with the key
}
}
} catch (IOException e) {
e.printStackTrace();
}
在调试器中为我打印整个页面,我可以在浏览器中显示它吗
我正在使用apache的HttpClient
是否可以以某种方式将响应转换为URI,然后使用
java.awt.Desktop.getDesktop().browse(响应)代码>为了在浏览器中显示您的响应,您需要从web客户端而不是从java客户端调用Servlet。
如果您的请求是HTTP GET请求,您可以通过在浏览器中键入URL来调用它。否则,您需要一个HTML表单来访问Servlet 您可以将响应写入一个文件,然后在浏览器中打开该文件。噢,多可怜的家伙!我使用POST。所以不可能将响应转换为URI?响应不是URI-响应是内容(文本、html、xml、json等)。可以将请求发送到servlet的URI。因为您使用POST,所以需要一个HTTP表单和带有servlet URL的POST方法。