關於代理轉發,代碼以下具體還有待理解

URLConnection conn;
				// 使用代理
				InetSocketAddress addr = new InetSocketAddress("10.37.84.36", 8080);
				Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
				PrintWriter out = null;
				String result = "";
				BufferedReader in = null;
				
		            // 獲取URLConnection對象對應的輸出流  

				    conn = realUrl.openConnection(proxy);
				    conn.setRequestProperty("Accept-Charset", "GBK");
					conn.setRequestProperty("contentType", "GBK");
					conn.setRequestProperty("accept", "*");
					conn.setRequestProperty("connection", "Keep-Alive");
					conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
					// 發送POST請求必須設置以下兩行
					conn.setDoOutput(true);
					conn.setDoInput(true);
					// 獲取URLConnection對象對應的輸出流
					out = new PrintWriter(conn.getOutputStream());
					// 發送請求參數
					out.print(makeXml());
					// flush輸出流的緩衝
					out.flush();
					// 定義BufferedReader輸入流來讀取URL的響應
					in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
					String line;
					System.out.println("======");
					while ((line = in.readLine()) != null) {
						result += new String(line);
						System.out.println(result);
					}
相關文章
相關標籤/搜索