Code
1 import java.io.BufferedReader;
2 import java.io.InputStreamReader;
3 import java.io.PrintWriter;
4 import java.io.OutputStreamWriter;
5 import java.net.*;
6 import java.util.Enumeration;
7
8 public class Proxy extends javax.servlet.http.HttpServlet {
9 protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
10 throws javax.servlet.ServletException, java.io.IOException {
11 response.setContentType("text/html;charset=GB2312");
12 String url = request.getParameter("url");
13 StringBuffer param = new StringBuffer();
14 Enumeration enu = request.getParameterNames();
15 int total = 0;
16 while(enu.hasMoreElements()){
17 String name = (String)enu.nextElement();
18 if(!name.equals("url")){
19 if(total == 0){
20 param.append(name).append("=").append(URLEncoder.encode(request.getParameter(name),"UTF-8"));
21 } else{
22 param.append("&").append(name).append("=").append(URLEncoder.encode(request.getParameter(name),"UTF-8"));
23 }
24 total++;
25
26 }
27 }
28 PrintWriter out = response.getWriter();
29 if(url != null){
30 URL connect = new URL(url.toString());
31 URLConnection connection = connect.openConnection();
32 connection.setDoOutput(true);
33 OutputStreamWriter paramout = new OutputStreamWriter(connection.getOutputStream());
34 paramout.write(param.toString());
35 paramout.flush();
36 BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"GB2312"));
37 String line;
38 while((line = reader.readLine()) != null){
39 out.println(line);
40 }
41 paramout.close();
42 reader.close();
43 }
44
45 }
46 protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {
47 response.setContentType("text/html;charset=GB2312");
48 StringBuffer url = new StringBuffer();
49 url.append(request.getParameter("url"));
50 Enumeration enu = request.getParameterNames();
51 int total = 0;
52 while(enu.hasMoreElements()){
53 String name = (String)enu.nextElement();
54 if(!name.equals("url")){
55 if(total == 0){
56 url.append("?").append(name).append("=").append(URLEncoder.encode(request.getParameter(name),"UTF-8"));
57 } else{
58 url.append("&").append(name).append("=").append(URLEncoder.encode(request.getParameter(name),"UTF-8"));
59 }
60 total++;
61
62 }
63 }
64 PrintWriter out = response.getWriter();
65 if(url != null){
66 URL connect = new URL(url.toString());
67 BufferedReader reader = new BufferedReader(new InputStreamReader(connect.openStream(),"GB2312"));
68 String line;
69 while((line = reader.readLine()) != null){
70 out.println(line);
71 }
72 reader.close();
73 }
74
75 http://www.sohu.com/index.html?name=123&id=000
76 Proxy?url=http://www.sohu.com/index.html&name=123&id=000
77
78 url=http://www.sohu.com/index.html&name=123&id=000
79
80 http://www.sohu.com/index.html?id=000&name=123
81
82 //我们
83 }
84 }
85
1 import java.io.BufferedReader;
2 import java.io.InputStreamReader;
3 import java.io.PrintWriter;
4 import java.io.OutputStreamWriter;
5 import java.net.*;
6 import java.util.Enumeration;
7
8 public class Proxy extends javax.servlet.http.HttpServlet {
9 protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
10 throws javax.servlet.ServletException, java.io.IOException {
11 response.setContentType("text/html;charset=GB2312");
12 String url = request.getParameter("url");
13 StringBuffer param = new StringBuffer();
14 Enumeration enu = request.getParameterNames();
15 int total = 0;
16 while(enu.hasMoreElements()){
17 String name = (String)enu.nextElement();
18 if(!name.equals("url")){
19 if(total == 0){
20 param.append(name).append("=").append(URLEncoder.encode(request.getParameter(name),"UTF-8"));
21 } else{
22 param.append("&").append(name).append("=").append(URLEncoder.encode(request.getParameter(name),"UTF-8"));
23 }
24 total++;
25
26 }
27 }
28 PrintWriter out = response.getWriter();
29 if(url != null){
30 URL connect = new URL(url.toString());
31 URLConnection connection = connect.openConnection();
32 connection.setDoOutput(true);
33 OutputStreamWriter paramout = new OutputStreamWriter(connection.getOutputStream());
34 paramout.write(param.toString());
35 paramout.flush();
36 BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"GB2312"));
37 String line;
38 while((line = reader.readLine()) != null){
39 out.println(line);
40 }
41 paramout.close();
42 reader.close();
43 }
44
45 }
46 protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {
47 response.setContentType("text/html;charset=GB2312");
48 StringBuffer url = new StringBuffer();
49 url.append(request.getParameter("url"));
50 Enumeration enu = request.getParameterNames();
51 int total = 0;
52 while(enu.hasMoreElements()){
53 String name = (String)enu.nextElement();
54 if(!name.equals("url")){
55 if(total == 0){
56 url.append("?").append(name).append("=").append(URLEncoder.encode(request.getParameter(name),"UTF-8"));
57 } else{
58 url.append("&").append(name).append("=").append(URLEncoder.encode(request.getParameter(name),"UTF-8"));
59 }
60 total++;
61
62 }
63 }
64 PrintWriter out = response.getWriter();
65 if(url != null){
66 URL connect = new URL(url.toString());
67 BufferedReader reader = new BufferedReader(new InputStreamReader(connect.openStream(),"GB2312"));
68 String line;
69 while((line = reader.readLine()) != null){
70 out.println(line);
71 }
72 reader.close();
73 }
74
75 http://www.sohu.com/index.html?name=123&id=000
76 Proxy?url=http://www.sohu.com/index.html&name=123&id=000
77
78 url=http://www.sohu.com/index.html&name=123&id=000
79
80 http://www.sohu.com/index.html?id=000&name=123
81
82 //我们
83 }
84 }
85