(String hostAddr, int port, String proxyAddr, int proxyPort, String userName, String userPass)
| 33 | private HttpProxyConnection() {} |
| 34 | |
| 35 | public static HttpProxyConnection open(String hostAddr, int port, String proxyAddr, int proxyPort, String userName, String userPass) throws IOException{ |
| 36 | HttpProxyConnection pconn=new HttpProxyConnection(); |
| 37 | |
| 38 | pconn.conn = new Socket(proxyAddr, proxyPort); |
| 39 | pconn.is=pconn.conn.getInputStream(); |
| 40 | pconn.os=pconn.conn.getOutputStream(); |
| 41 | String auth = "Proxy-Authorization: Basic "; |
| 42 | String req = ""; |
| 43 | if (userName.length()>0 && userPass.length()>0) { |
| 44 | auth += Strconv.toBase64(userName + ":" + userPass); |
| 45 | req = "CONNECT " + hostAddr + ":" + port + " HTTP/1.0\r\nHost: " + hostAddr |
| 46 | + "\r\n" + auth + "\r\nPragma: no-cache\r\n\r\n"; |
| 47 | } else { |
| 48 | |
| 49 | req= "CONNECT " + hostAddr + ":" + port + " HTTP/1.0\r\nHost: " + hostAddr |
| 50 | + "\r\nPragma: no-cache\r\n\r\n"; |
| 51 | } |
| 52 | |
| 53 | pconn.os.write(req.getBytes()); |
| 54 | |
| 55 | String inpLine=pconn.readLine(); |
| 56 | if (inpLine.indexOf("200",0)<=0) throw new IOException(inpLine); |
| 57 | while (inpLine.length()>0) { |
| 58 | inpLine=pconn.readLine(); |
| 59 | } |
| 60 | |
| 61 | return pconn; |
| 62 | } |
| 63 | |
| 64 | public String readLine() throws IOException { |
| 65 | StringBuffer buf=new StringBuffer(); |
no test coverage detected