Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Proxy getProxyAuthorizationInstance(){
- Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
- Authenticator authenticator = new Authenticator() {
- @Override
- public PasswordAuthentication getPasswordAuthentication() {
- return (new PasswordAuthentication(username,
- password.toCharArray()));
- }
- };
- Authenticator.setDefault(authenticator);
- System.out.println(host + " " + port + " " + username + " " + password);
- return proxy;
- }
- private String sendRequestToGetIPData(){
- HttpURLConnection con = null;
- StringBuilder json = new StringBuilder();
- MyProxy proxy = new MyProxy("", 0, "", "");
- try {
- URL url = new URL("https://ipapi.co/json");
- con = (HttpURLConnection) url.openConnection(proxy.getProxyAuthorizationInstance());
- con.setRequestMethod("POST");
- con.setConnectTimeout(10000);
- con.setReadTimeout(10000);
- int responseCode = con.getResponseCode();
- appendToTextArea("Sending " + con.getRequestMethod() + " request to URL : " + url);
- appendToTextArea("Response Code : " + responseCode);
- BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
- String inputLine;
- json = new StringBuilder();
- while ((inputLine = in.readLine()) != null) {
- json.append(inputLine);
- }
- in.close();
- } catch (Exception e){
- appendToTextArea(e.getLocalizedMessage() + "\n" + proxy.getHost() + " : " + proxy.getPort() + " " + proxy.getUsername() + " " + proxy.getPassword());
- e.printStackTrace();
- } finally {
- if (con != null) {
- con.disconnect();
- }
- }
- return json.toString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement