Advertisement
Guest User

Untitled

a guest
Mar 7th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. <%@ page language="java" import="java.net.Authenticator,java.net.PasswordAuthentication,java.io.BufferedReader,java.net.*,java.io.*" contentType="text/html; charset=ISO-8859-1"
  2. pageEncoding="ISO-8859-1"%>
  3. <%
  4.  
  5. String urlToQuery = request.getParameter("url");
  6. System.out.println(" " +urlToQuery);
  7. //URL url = new URL(urlToQuery);
  8.  
  9.  
  10.  
  11. //InputStream in = conn.getInputStream();
  12.  
  13. String urlString = "";
  14. String username = "";
  15. String password = "";
  16. Authenticator.setDefault(new MyAuthenticator(username, password));
  17. URL url = new URL(urlToQuery);
  18. URLConnection conn = url.openConnection();
  19. InputStream content = (InputStream) url.getContent();
  20. BufferedReader in = new BufferedReader(new InputStreamReader(content));
  21. String line;
  22. while ((line = in.readLine()) != null) {
  23. System.out.println(line);
  24. }
  25. System.out.println("Done.");
  26.  
  27. class MyAuthenticator extends Authenticator {
  28. private String username, password;
  29.  
  30. public MyAuthenticator(String user, String pass) {
  31. username = user;
  32. password = pass;
  33. }
  34.  
  35. protected PasswordAuthentication getPasswordAuthentication() {
  36. System.out.println("Requesting Host : " + getRequestingHost());
  37. System.out.println("Requesting Port : " + getRequestingPort());
  38. System.out.println("Requesting Prompt : " + getRequestingPrompt());
  39. System.out.println("Requesting Protocol: " + getRequestingProtocol());
  40. System.out.println("Requesting Scheme : " + getRequestingScheme());
  41. System.out.println("Requesting Site : " + getRequestingSite());
  42. return new PasswordAuthentication(username, password.toCharArray());
  43. }
  44. }
  45.  
  46.  
  47.  
  48. %>
  49.  
  50. <%=line %>
  51.  
  52. public class MyJSP extends Servlet {
  53. public void service(HttpRequest request, HttpResponse response) {
  54. /** JSP CODE HERE **/
  55. }
  56. }
  57.  
  58. Authenticator.setDefault(new Authenticator() {
  59. protected getPasswordAuthentication() {
  60. System.out.println("Requesting Host : " + getRequestingHost());
  61. System.out.println("Requesting Port : " + getRequestingPort());
  62. ...
  63. }
  64. });
  65.  
  66. <%@ page language="java" import="java.net.Authenticator,java.net.PasswordAuthentication,java.io.BufferedReader,java.net.*,java.io.*" contentType="text/html; charset=ISO-8859-1"
  67. pageEncoding="ISO-8859-1"%>
  68. <%
  69.  
  70. class MyAuthenticator extends Authenticator {
  71. private String username, password;
  72.  
  73. public MyAuthenticator(String user, String pass) {
  74. username = user;
  75. password = pass;
  76. }
  77.  
  78. protected PasswordAuthentication getPasswordAuthentication() {
  79. System.out.println("Requesting Host : " + getRequestingHost());
  80. System.out.println("Requesting Port : " + getRequestingPort());
  81. System.out.println("Requesting Prompt : " + getRequestingPrompt());
  82. System.out.println("Requesting Protocol: " + getRequestingProtocol());
  83. System.out.println("Requesting Scheme : " + getRequestingScheme());
  84. System.out.println("Requesting Site : " + getRequestingSite());
  85. return new PasswordAuthentication(username, password.toCharArray());
  86. }
  87. }
  88.  
  89. String urlToQuery = request.getParameter("url");
  90. System.out.println(" " +urlToQuery);
  91. //URL url = new URL(urlToQuery);
  92.  
  93.  
  94.  
  95. //InputStream in = conn.getInputStream();
  96.  
  97. String urlString = "";
  98. String username = "";
  99. String password = "";
  100. Authenticator.setDefault(new MyAuthenticator(username, password));
  101. URL url = new URL(urlToQuery);
  102. URLConnection conn = url.openConnection();
  103. InputStream content = (InputStream) url.getContent();
  104. BufferedReader in = new BufferedReader(new InputStreamReader(content));
  105. String line;
  106. while ((line = in.readLine()) != null) {
  107. System.out.println(line);
  108. }
  109. System.out.println("Done.");
  110.  
  111.  
  112.  
  113.  
  114.  
  115. %>
  116.  
  117. <%=line %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement