Search in sources :

Example 21 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project PowerNukkitX by PowerNukkitX.

the class VersionListHelper method listRemoteLibs.

public static List<LibEntry> listRemoteLibs() {
    if (cache.containsKey("libs")) {
        return exactLibs(cache.get("libs"));
    } else {
        final HttpRequest request = HttpRequest.get(OSS + "?" + "list-type=2" + "&" + "prefix=libs" + "/&" + "max-keys=100" + "&" + "delimiter=/");
        final String result = request.body(HttpRequest.CHARSET_UTF8);
        cache.put("libs", result);
        return exactLibs(result);
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest)

Example 22 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project PowerNukkitX by PowerNukkitX.

the class GraalVMInstall method downloadGraalVM17.

@SuppressWarnings("ResultOfMethodCallIgnored")
private void downloadGraalVM17() {
    final File localJavaDir = new File("./java");
    if (!localJavaDir.exists()) {
        localJavaDir.mkdirs();
    }
    final URL downloadURL = URLUtils.graal17URL();
    if (downloadURL == null) {
        Logger.trWarn("display.fail.install-java17");
        return;
    }
    try {
        final File targetZip = new File("tmp.zip");
        HttpRequest request = HttpRequest.get(downloadURL);
        Logger.trInfo("display.connecting", downloadURL.toString());
        final AtomicLong atomicLong = new AtomicLong(0);
        cli.timer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                final long total = request.getConnection().getContentLength();
                final long finished = targetZip.length();
                final long speed = finished - atomicLong.get();
                atomicLong.set(finished);
                Logger.bar((float) (finished * 1.0 / total), displayableBytes(finished) + "/" + displayableBytes(total) + " (" + displayableBytes(speed) + "/s)");
                if (finished == total) {
                    Logger.trInfo("display.success.download", "Java17");
                    this.cancel();
                }
            }
        }, 500, 500);
        request.receive(targetZip);
    } catch (Exception e) {
        Logger.trWarn("display.fail.install-java17");
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) TimerTask(java.util.TimerTask) ZipFile(net.lingala.zip4j.ZipFile) File(java.io.File) URL(java.net.URL) IOException(java.io.IOException)

Example 23 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project PowerNukkitX by PowerNukkitX.

the class URLUtils method downloadWithBar.

public static void downloadWithBar(URL downloadURL, File target, String displayName, Timer timer) {
    try {
        HttpRequest request = HttpRequest.get(downloadURL);
        Logger.trInfo("display.connecting", downloadURL.toString());
        Logger.newLine();
        final AtomicLong atomicLong = new AtomicLong(0);
        timer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                final long finished = target.length();
                final long total = request.getConnection().getContentLength();
                final long speed = finished - atomicLong.get();
                atomicLong.set(finished);
                Logger.bar((float) (finished * 1.0 / total), displayableBytes(finished) + "/" + displayableBytes(total) + " (" + displayableBytes(speed) + "/s)");
                if (finished == total) {
                    this.cancel();
                }
            }
        }, 500, 500);
        request.receive(target);
        Logger.clearUpLine();
        Logger.trInfo("display.success.download", displayName);
    } catch (Exception e) {
        Logger.trWarn("display.fail.download", displayName);
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) TimerTask(java.util.TimerTask) MalformedURLException(java.net.MalformedURLException)

Example 24 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project sunlogin-exp-gui by theLSA.

the class GetSunloginInfo method get_sunlogin_vuln_api_port.

public boolean get_sunlogin_vuln_api_port() {
    // HttpRequest responseRst = HttpRequest.get("https://www.baidu.com");
    String ip = url.split(":")[0];
    int port = Integer.valueOf(url.split(":")[1]).intValue();
    // ipWithPort.split(":")[0],Integer.valueOf(ipWithPort.split(":")[1]).intValue(),httpTimeout
    try {
        HttpRequest responseRst = HttpRequest.get("http://" + ip + ":" + port).connectTimeout(httpTimeout).readTimeout(httpTimeout);
        String responseBody = responseRst.body();
        String sunloginVulnApiPortFingerprint = "{\"success\":false,\"msg\":\"Verification failure\"}";
        if (responseBody.contains(sunloginVulnApiPortFingerprint)) {
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        // TODO: handle exception
        return false;
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest)

Example 25 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project springboot by LiJinHongPassion.

the class CrawlerImageUtil method defaultGetIPs.

/**
 * 爬取代理ip + 端口:前三页
 */
public static void defaultGetIPs() {
    Map<String, String> headers = new HashMap<>();
    headers.put("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
    // 解决乱码
    // headers.put("accept-encoding", "gzip, deflate, br");
    // headers.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36");
    headers.put("user-agent", rl.getStringOfFile());
    for (int i = 1; i < 4; i++) {
        HttpRequest httpRequest = HttpRequest.get(ipurl + i).headers(headers);
        // httpRequest.useProxy("171.35.162.12", 9999);
        String s = httpRequest.body().replaceAll(" ", "").replaceAll("\r\n", "").replaceAll("\n", "").replaceAll("\t", "").replaceAll("\\\\", "");
        // 现在创建 matcher 对象
        Matcher m = Pattern.compile("<td>[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}</td><td>[0-9]{2,6}</td>").matcher(s);
        while (m.find()) {
            try {
                String ip = m.group();
                ip = ip.replaceAll("</td><td>", "|").replaceAll("<[/]*td>", "");
                ips.add(new IPEntity(ip.substring(0, ip.indexOf("|")), ip.substring(ip.indexOf("|") + 1)));
            } catch (Exception e) {
            }
        }
    }
    if (ips.size() > 0) {
        StringBuilder re = new StringBuilder();
        for (int j = 0; j < ips.size(); j++) {
            re.append(ips.get(j).toString());
        }
        FileUtil.getFile(re.toString().getBytes(), "./env/ip/", "ips--" + System.currentTimeMillis() + ".txt");
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) IPEntity(com.example.li.springboot_crawler_demo.utils.img.entity.IPEntity) Matcher(java.util.regex.Matcher)

Aggregations

HttpRequest (com.github.kevinsawicki.http.HttpRequest)86 HttpRequestException (com.github.kevinsawicki.http.HttpRequest.HttpRequestException)29 IOException (java.io.IOException)25 JSONObject (org.json.JSONObject)19 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 File (java.io.File)8 TimerTask (java.util.TimerTask)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)8 Pair (android.util.Pair)6 URL (java.net.URL)5 JSONException (org.json.JSONException)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)4 JSONObject (com.alibaba.fastjson.JSONObject)4 ZipFile (net.lingala.zip4j.ZipFile)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)3 IPEntity (com.example.li.springboot_crawler_demo.utils.img.entity.IPEntity)2 HttpURLConnection (java.net.HttpURLConnection)2 MalformedURLException (java.net.MalformedURLException)2 Matcher (java.util.regex.Matcher)2 JSONArray (org.json.JSONArray)2