Search in sources :

Example 1 with HttpHeadsInfo

use of lee.study.down.model.HttpHeadsInfo in project proxyee-down by monkeyWie.

the class HttpDownUtil method buildGetRequest.

public static HttpRequestInfo buildGetRequest(String url, Map<String, String> heads, String body) throws MalformedURLException {
    URL u = new URL(url);
    HttpHeadsInfo headsInfo = new HttpHeadsInfo();
    headsInfo.add("Host", u.getHost());
    headsInfo.add("Connection", "keep-alive");
    headsInfo.add("Upgrade-Insecure-Requests", "1");
    headsInfo.add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36");
    headsInfo.add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
    headsInfo.add("Referer", u.getHost());
    headsInfo.add("Accept-Encoding", "gzip, deflate, br");
    headsInfo.add("Accept-Language", "zh-CN,zh;q=0.9");
    if (heads != null) {
        for (Entry<String, String> entry : heads.entrySet()) {
            headsInfo.set(entry.getKey(), entry.getValue());
        }
    }
    byte[] content = null;
    if (body != null && body.length() > 0) {
        content = body.getBytes();
        headsInfo.add("Content-Length", content.length);
    }
    HttpRequestInfo requestInfo = new HttpRequestInfo(HttpVer.HTTP_1_1, HttpMethod.GET.toString(), url, headsInfo, content);
    requestInfo.setRequestProto(ProtoUtil.getRequestProto(requestInfo));
    return requestInfo;
}
Also used : HttpHeadsInfo(lee.study.down.model.HttpHeadsInfo) HttpRequestInfo(lee.study.down.model.HttpRequestInfo) URL(java.net.URL)

Aggregations

URL (java.net.URL)1 HttpHeadsInfo (lee.study.down.model.HttpHeadsInfo)1 HttpRequestInfo (lee.study.down.model.HttpRequestInfo)1