cn.hutool.http.HttpResponse Java Examples

The following examples show how to use cn.hutool.http.HttpResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OcrUtils.java    From tools-ocr with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static String sogouWebOcr(byte[] imgData) {
    String url = "https://deepi.sogou.com/api/sogouService";
    String referer = "https://deepi.sogou.com/?from=picsearch&tdsourcetag=s_pctim_aiomsg";
    String imageData = Base64.encode(imgData);
    long t = System.currentTimeMillis();
    String sign = SecureUtil.md5("sogou_ocr_just_for_deepibasicOpenOcr" + t + imageData.substring(0, Math.min(1024, imageData.length())) + "4b66a37108dab018ace616c4ae07e644");
    Map<String, Object> data = new HashMap<>();
    data.put("image", imageData);
    data.put("lang", "zh-Chs");
    data.put("pid", "sogou_ocr_just_for_deepi");
    data.put("salt", t);
    data.put("service", "basicOpenOcr");
    data.put("sign", sign);
    HttpRequest request = HttpUtil.createPost(url).timeout(15000);
    request.form(data);
    request.header("Referer", referer);
    HttpResponse response = request.execute();
    return extractSogouResult(WebUtils.getSafeHtml(response));
}
 
Example #2
Source File: CommUtils.java    From tools-ocr with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static String postMultiData(String url, byte[] data, String boundary, String cookie, String referer) {
    try {
        HttpRequest request = HttpUtil.createPost(url).timeout(15000);
        request.contentType("multipart/form-data; boundary=" + boundary);
        request.body(data);
        if (StrUtil.isNotBlank(referer)) {
            request.header("Referer", referer);
        }
        if (StrUtil.isNotBlank(cookie)) {
            request.cookie(cookie);
        }
        HttpResponse response = request.execute();
        return WebUtils.getSafeHtml(response);
    } catch (Exception ex) {
        StaticLog.error(ex);
        return null;
    }
}
 
Example #3
Source File: OcrUtils.java    From tools-ocr with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static String bdBaseOcr(byte[] imgData, String type){
    String[] urlArr = new String[]{"http://ai.baidu.com/tech/ocr/general", "http://ai.baidu.com/index/seccode?action=show"};
    StringBuilder cookie = new StringBuilder();
    for (String url : urlArr) {
        HttpResponse cookieResp = WebUtils.get(url);
        List<String> ckList = cookieResp.headerList("Set-Cookie");
        for (String s : ckList) {
            cookie.append(s.replaceAll("expires[\\S\\s]+", ""));
        }
    }
    HashMap<String, String> header = new HashMap<>();
    header.put("Referer", "http://ai.baidu.com/tech/ocr/general");
    header.put("Cookie", cookie.toString());
    String data = "type="+URLUtil.encodeQuery(type)+"&detect_direction=false&image_url&image=" + URLUtil.encodeQuery("data:image/jpeg;base64," + Base64.encode(imgData)) + "&language_type=CHN_ENG";
    HttpResponse response = WebUtils.postRaw("http://ai.baidu.com/aidemo", data, 0, header);
    return extractBdResult(WebUtils.getSafeHtml(response));
}
 
Example #4
Source File: TomcatManageService.java    From Jpom with MIT License 6 votes vote down vote up
/**
 * 查询tomcat状态
 *
 * @param id tomcat的id
 * @return tomcat状态0表示未运行,1表示运行中
 */
public int getTomcatStatus(String id) {
    int result = 0;
    TomcatInfoModel tomcatInfoModel = tomcatEditService.getItem(id);
    String url = String.format("http://127.0.0.1:%d/", tomcatInfoModel.getPort());
    HttpRequest httpRequest = new HttpRequest(url);
    // 设置超时时间为3秒
    httpRequest.setConnectionTimeout(3000);
    try {
        HttpResponse httpResponse = httpRequest.execute();
        result = 1;
    } catch (Exception ignored) {
    }

    return result;
}
 
Example #5
Source File: TomcatManageService.java    From Jpom with MIT License 6 votes vote down vote up
/**
 * 访问tomcat Url
 *
 * @param tomcatInfoModel tomcat信息
 * @param cmd             命令
 * @return 访问结果
 */
private String tomcatCmd(TomcatInfoModel tomcatInfoModel, String cmd) {
    String url = String.format("http://127.0.0.1:%d/jpomAgent/%s", tomcatInfoModel.getPort(), cmd);
    HttpRequest httpRequest = new HttpRequest(url);
    // 设置超时时间为3秒
    httpRequest.setConnectionTimeout(3000);
    String body = "";

    try {
        HttpResponse httpResponse = httpRequest.execute();
        if (httpResponse.isOk()) {
            body = httpResponse.body();
        }
        if (httpResponse.getStatus() == HttpStatus.HTTP_NOT_FOUND) {
            // 没有插件
            tomcatInfoModel.initTomcat();
            throw new JpomRuntimeException("tomcat 未初始化,已经重新初始化请稍后再试");
        }
    } catch (JpomRuntimeException jpom) {
        throw jpom;
    } catch (Exception ignored) {
    }

    return body;
}
 
Example #6
Source File: ManualOperateController.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 测试手动保存任务
 */
@GetMapping("/add")
public String xxlJobAdd() {
    Map<String, Object> jobInfo = Maps.newHashMap();
    jobInfo.put("jobGroup", 2);
    jobInfo.put("jobCron", "0 0/1 * * * ? *");
    jobInfo.put("jobDesc", "手动添加的任务");
    jobInfo.put("author", "admin");
    jobInfo.put("executorRouteStrategy", "ROUND");
    jobInfo.put("executorHandler", "demoTask");
    jobInfo.put("executorParam", "手动添加的任务的参数");
    jobInfo.put("executorBlockStrategy", ExecutorBlockStrategyEnum.SERIAL_EXECUTION);
    jobInfo.put("glueType", GlueTypeEnum.BEAN);

    HttpResponse execute = HttpUtil.createGet(baseUri + JOB_INFO_URI + "/add").form(jobInfo).execute();
    log.info("【execute】= {}", execute);
    return execute.body();
}
 
Example #7
Source File: AbstractOneDriveServiceBase.java    From zfile with MIT License 6 votes vote down vote up
/**
 * 根据 RefreshToken 刷新 AccessToken, 返回刷新后的 Token.
 *
 * @return  刷新后的 Token
 */
public OneDriveToken getRefreshToken() {
    StorageConfig refreshStorageConfig =
            storageConfigRepository.findByDriveIdAndKey(driveId, StorageConfigConstant.REFRESH_TOKEN_KEY);

    String param = "client_id=" + getClientId() +
            "&redirect_uri=" + getRedirectUri() +
            "&client_secret=" + getClientSecret() +
            "&refresh_token=" + refreshStorageConfig.getValue() +
            "&grant_type=refresh_token";

    String fullAuthenticateUrl = AUTHENTICATE_URL.replace("{authenticateEndPoint}", getAuthenticateEndPoint());
    HttpRequest post = HttpUtil.createPost(fullAuthenticateUrl);

    post.body(param, "application/x-www-form-urlencoded");
    HttpResponse response = post.execute();
    return JSONObject.parseObject(response.body(), OneDriveToken.class);
}
 
Example #8
Source File: AbstractOneDriveServiceBase.java    From zfile with MIT License 6 votes vote down vote up
/**
 * OAuth2 协议中, 根据 code 换取 access_token 和 refresh_token.
 *
 * @param   code
 *          代码
 *
 * @return  获取的 Token 信息.
 */
public OneDriveToken getToken(String code) {
    String param = "client_id=" + getClientId() +
            "&redirect_uri=" + getRedirectUri() +
            "&client_secret=" + getClientSecret() +
            "&code=" + code +
            "&scope=" + getScope() +
            "&grant_type=authorization_code";

    String fullAuthenticateUrl = AUTHENTICATE_URL.replace("{authenticateEndPoint}", getAuthenticateEndPoint());
    HttpRequest post = HttpUtil.createPost(fullAuthenticateUrl);

    post.body(param, "application/x-www-form-urlencoded");
    HttpResponse response = post.execute();
    return JSONObject.parseObject(response.body(), OneDriveToken.class);
}
 
Example #9
Source File: Test1.java    From SubTitleSearcher with Apache License 2.0 6 votes vote down vote up
public static String getUrl(String url) {
	try {
		HttpResponse response = HttpRequest.get(url).execute();

		System.out.println(response.toString());
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return getUrl(location);
		} else if (statusCode == 200) {
			return response.body();
		} else {
			System.out.println(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	} finally {
	}
}
 
Example #10
Source File: Test1.java    From SubTitleSearcher with Apache License 2.0 6 votes vote down vote up
public static String getUrl(String url) {
	try {
		HttpResponse response = HttpRequest.get(url).execute();

		System.out.println(response.toString());
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return getUrl(location);
		} else if (statusCode == 200) {
			return response.body();
		} else {
			System.out.println(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	} finally {
	}
}
 
Example #11
Source File: ZIMuKuCommon.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载字幕
 * @param url
 * @return
 */
public static JSONObject downContent(String url) {
	String result = httpGet(baseUrl+url);
	String downUrl = RegexUtil.getMatchStr(result, 
			"<a\\s+id=\"down1\"\\s+href=\"([^\"]*/dld/[\\w]+\\.html)\""
			, Pattern.DOTALL);
	if(downUrl == null)return null;
	if(!downUrl.startsWith("http")) {
		downUrl = baseUrl + downUrl;
	}
	
	result = httpGet(downUrl);
	if(result == null)return null;
	//System.out.println(result);
	JSONArray resList = RegexUtil.getMatchList(result, 
			"<li><a\\s+rel=\"nofollow\"\\s+href=\"([^\"]*/download/[^\"]+)\"", Pattern.DOTALL);
	if(resList == null || resList.size() == 0 || resList.getJSONArray(0).size() == 0)return null;
	//HtHttpUtil.http.debug=true;
	HttpResponse httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(0).getStr(0)), null, downUrl);
	int i = 0;
	while(httpResp == null && resList.size() > ++i) {
		httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(1).getStr(0)), null, downUrl);
	}
	//System.out.println(httpResp);
	if(httpResp == null)return null;
	String filename = HtHttpUtil.getFileName(httpResp);
	byte[] data = httpResp.bodyBytes();
	//System.out.println(filename);
	JSONObject resp = new JSONObject();
	resp.put("filename", filename);
	resp.put("ext", StringUtil.extName(filename).toLowerCase());
	resp.put("data", Base64.encode(data));
	
	return resp;
}
 
Example #12
Source File: ManualOperateController.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试手动启动任务
 */
@GetMapping("/start")
public String xxlJobStart() {
    Map<String, Object> jobInfo = Maps.newHashMap();
    jobInfo.put("id", 4);

    HttpResponse execute = HttpUtil.createGet(baseUri + JOB_INFO_URI + "/start").form(jobInfo).execute();
    log.info("【execute】= {}", execute);
    return execute.body();
}
 
Example #13
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 获取头部文件名配置 Content-Disposition=[attachment;
 * filename="Downsizing.2017.1080p.Bluray.MKV.x264.AC3.ass"]
 * 
 * @param resp
 * @return
 */
public static String getFileName(HttpResponse resp) {
	String desp = new String(resp.header("Content-Disposition").getBytes(CharsetUtil.CHARSET_ISO_8859_1),
			CharsetUtil.CHARSET_UTF_8);
	if (desp == null || desp.indexOf("filename") == -1)
		return null;
	return RegexUtil.getMatchStr(desp, "filename=\"([^\"]+)\"");
}
 
Example #14
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public String get(String url, String charset, String ua, String refer) {
	logger.info("get=" + url);

	try {
		HttpResponse response = addHeader(HttpRequest.get(url).header(Header.USER_AGENT, ua)
				.header(Header.ACCEPT_CHARSET, charset).charset(charset)
				.header(Header.ACCEPT, _accept).header(Header.ACCEPT_ENCODING, _accept_encoding)
				.header(Header.REFERER, refer != null ? refer : url)
				.header(Header.ACCEPT_LANGUAGE, _accept_language).timeout(_time_out)).execute();

		if (debug) {
			logger.info(response.toString());
		}
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return get(location, charset, ua, refer);
		} else if (statusCode == 200) {
			return response.body();
		} else {
			logger.error(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		logger.error(e);
		return null;
	} finally {
	}
}
 
Example #15
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public String post(String url, Map<String, Object> list, String charset, String ua, String refer) {
	logger.info("post=" + url);
	try {
		HttpResponse response = addHeader(HttpRequest.post(url).form(list).header(Header.USER_AGENT, ua)
				.header(Header.ACCEPT_CHARSET, charset).charset(charset)
				.header(Header.ACCEPT, _accept).header(Header.ACCEPT_ENCODING, _accept_encoding)
				.header(Header.REFERER, refer != null ? refer : url)
				.header(Header.ACCEPT_LANGUAGE, _accept_language).timeout(_time_out)).execute();

		if (debug) {
			logger.info("response header:" + getRespHeaderStr(response));
		}
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return post(location, list, charset, ua, refer);
		} else if (statusCode == 200) {
			return response.body();
		} else {
			logger.error(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		logger.error(e);
		return null;
	} finally {
	}
}
 
Example #16
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public String postStream(String url, String data, String charset, String ua, String refer) {
	logger.info("postStream=" + url);
	try {
		HttpResponse response = addHeader(HttpRequest.post(url).body(data, _stream_media_type)
				.header(Header.USER_AGENT, ua).header(Header.ACCEPT_CHARSET, charset)
				.charset(charset).header(Header.ACCEPT, _accept)
				.header(Header.ACCEPT_ENCODING, _accept_encoding)
				.header(Header.REFERER, refer != null ? refer : url)
				.header(Header.ACCEPT_LANGUAGE, _accept_language).timeout(_time_out)).execute();

		if (debug) {
			logger.info("response header:" + getRespHeaderStr(response));
		}
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return postStream(location, data, charset, ua, refer);
		} else if (statusCode == 200) {
			return response.body();
		} else {
			logger.error(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		logger.error(e);
		return null;
	} finally {
	}

}
 
Example #17
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public String getRespHeaderStr(HttpResponse response) {
	StringBuilder sb = StrUtil.builder();
	sb.append("Response Headers: ").append(StrUtil.CRLF);
	Map<String, List<String>> headers = response.headers();
	for (Entry<String, List<String>> entry : headers.entrySet()) {
		sb.append("\t").append(entry).append(StrUtil.CRLF);
	}
	return sb.toString();
}
 
Example #18
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public HttpResponse getResponse(String url, String ua, String refer) {
	logger.info("getResponse=" + url);

	try {
		HttpResponse response = addHeader(HttpRequest.get(url).header(Header.USER_AGENT, ua)
				.header(Header.ACCEPT, _accept).header(Header.ACCEPT_ENCODING, _accept_encoding)
				.header(Header.REFERER, refer != null ? refer : url)
				.header(Header.ACCEPT_LANGUAGE, _accept_language).timeout(_time_out)).execute();

		if (debug) {
			logger.info("response header:" + getRespHeaderStr(response));
		}
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return getResponse(location, ua, refer);
		} else if (statusCode == 200) {
			return response;
		} else {
			logger.error(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		logger.error(e);
		return null;
	} finally {
	}
}
 
Example #19
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public byte[] getBytes(String url, String ua, String refer) {
	logger.info("getBytes=" + url);

	try {
		HttpResponse response = addHeader(HttpRequest.get(url).header(Header.USER_AGENT, ua)
				.header(Header.ACCEPT, _accept).header(Header.ACCEPT_ENCODING, _accept_encoding)
				.header(Header.REFERER, refer != null ? refer : url)
				.header(Header.ACCEPT_LANGUAGE, _accept_language).timeout(_time_out)).execute();

		if (debug) {
			logger.info("response header:" + getRespHeaderStr(response));
		}
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return getBytes(location, ua, refer);
		} else if (statusCode == 200) {
			return response.bodyBytes();
		} else {
			logger.error(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		logger.error(e);
		return null;
	} finally {
	}
}
 
Example #20
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public byte[] postBytes(String url, Map<String, Object> list, String ua, String refer) {
	logger.info("postBytes=" + url);

	try {
		HttpResponse response = addHeader(HttpRequest.post(url).form(list).header(Header.USER_AGENT, ua)
				.header(Header.ACCEPT, _accept).header(Header.ACCEPT_ENCODING, _accept_encoding)
				.header(Header.REFERER, refer != null ? refer : url)
				.header(Header.ACCEPT_LANGUAGE, _accept_language).timeout(_time_out)).execute();

		if (debug) {
			logger.info("response header:" + getRespHeaderStr(response));
		}
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return postBytes(location, list, ua, refer);
		} else if (statusCode == 200) {
			return response.bodyBytes();
		} else {
			logger.error(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		logger.error(e);
		return null;
	} finally {
	}
}
 
Example #21
Source File: ZIMuKuCommon.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载字幕
 * @param url
 * @return
 */
public static JSONObject downContent(String url) {
	String result = httpGet(baseUrl+url);
	String downUrl = RegexUtil.getMatchStr(result, 
			"<a\\s+id=\"down1\"\\s+href=\"([^\"]*/dld/[\\w]+\\.html)\""
			, Pattern.DOTALL);
	if(downUrl == null)return null;
	if(!downUrl.startsWith("http")) {
		downUrl = baseUrl + downUrl;
	}
	
	result = httpGet(downUrl);
	if(result == null)return null;
	//System.out.println(result);
	JSONArray resList = RegexUtil.getMatchList(result, 
			"<li><a\\s+rel=\"nofollow\"\\s+href=\"([^\"]*/download/[^\"]+)\"", Pattern.DOTALL);
	if(resList == null || resList.size() == 0 || resList.getJSONArray(0).size() == 0)return null;
	//HtHttpUtil.http.debug=true;
	HttpResponse httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(0).getStr(0)), null, downUrl);
	int i = 0;
	while(httpResp == null && resList.size() > ++i) {
		httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(1).getStr(0)), null, downUrl);
	}
	//System.out.println(httpResp);
	if(httpResp == null)return null;
	String filename = HtHttpUtil.getFileName(httpResp);
	byte[] data = httpResp.bodyBytes();
	//System.out.println(filename);
	JSONObject resp = new JSONObject();
	resp.put("filename", filename);
	resp.put("ext", StringUtil.extName(filename).toLowerCase());
	resp.put("data", Base64.encode(data));
	
	return resp;
}
 
Example #22
Source File: ManualOperateController.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 任务组列表,xxl-job叫做触发器列表
 */
@GetMapping("/group")
public String xxlJobGroup() {
    HttpResponse execute = HttpUtil.createGet(baseUri + JOB_GROUP_URI + "/list").execute();
    log.info("【execute】= {}", execute);
    return execute.body();
}
 
Example #23
Source File: ManualOperateController.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 分页任务列表
 *
 * @param page 当前页,第一页 -> 0
 * @param size 每页条数,默认10
 * @return 分页任务列表
 */
@GetMapping("/list")
public String xxlJobList(Integer page, Integer size) {
    Map<String, Object> jobInfo = Maps.newHashMap();
    jobInfo.put("start", page != null ? page : 0);
    jobInfo.put("length", size != null ? size : 10);
    jobInfo.put("jobGroup", 2);
    jobInfo.put("triggerStatus", -1);

    HttpResponse execute = HttpUtil.createGet(baseUri + JOB_INFO_URI + "/pageList").form(jobInfo).execute();
    log.info("【execute】= {}", execute);
    return execute.body();
}
 
Example #24
Source File: ManualOperateController.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试手动触发一次任务
 */
@GetMapping("/trigger")
public String xxlJobTrigger() {
    Map<String, Object> jobInfo = Maps.newHashMap();
    jobInfo.put("id", 4);
    jobInfo.put("executorParam", JSONUtil.toJsonStr(jobInfo));

    HttpResponse execute = HttpUtil.createGet(baseUri + JOB_INFO_URI + "/trigger").form(jobInfo).execute();
    log.info("【execute】= {}", execute);
    return execute.body();
}
 
Example #25
Source File: ManualOperateController.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试手动删除任务
 */
@GetMapping("/remove")
public String xxlJobRemove() {
    Map<String, Object> jobInfo = Maps.newHashMap();
    jobInfo.put("id", 4);

    HttpResponse execute = HttpUtil.createGet(baseUri + JOB_INFO_URI + "/remove").form(jobInfo).execute();
    log.info("【execute】= {}", execute);
    return execute.body();
}
 
Example #26
Source File: ManualOperateController.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 测试手动停止任务
 */
@GetMapping("/stop")
public String xxlJobStop() {
    Map<String, Object> jobInfo = Maps.newHashMap();
    jobInfo.put("id", 4);

    HttpResponse execute = HttpUtil.createGet(baseUri + JOB_INFO_URI + "/stop").form(jobInfo).execute();
    log.info("【execute】= {}", execute);
    return execute.body();
}
 
Example #27
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public byte[] getBytes(String url, String ua, String refer) {
	logger.info("getBytes=" + url);

	try {
		HttpResponse response = addHeader(HttpRequest.get(url).header(Header.USER_AGENT, ua)
				.header(Header.ACCEPT, _accept).header(Header.ACCEPT_ENCODING, _accept_encoding)
				.header(Header.REFERER, refer != null ? refer : url)
				.header(Header.ACCEPT_LANGUAGE, _accept_language).timeout(_time_out)).execute();

		if (debug) {
			logger.info("response header:" + getRespHeaderStr(response));
		}
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return getBytes(location, ua, refer);
		} else if (statusCode == 200) {
			return response.bodyBytes();
		} else {
			logger.error(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		logger.error(e);
		return null;
	} finally {
	}
}
 
Example #28
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public HttpResponse getResponse(String url, String ua, String refer) {
	logger.info("getResponse=" + url);

	try {
		HttpResponse response = addHeader(HttpRequest.get(url).header(Header.USER_AGENT, ua)
				.header(Header.ACCEPT, _accept).header(Header.ACCEPT_ENCODING, _accept_encoding)
				.header(Header.REFERER, refer != null ? refer : url)
				.header(Header.ACCEPT_LANGUAGE, _accept_language).timeout(_time_out)).execute();

		if (debug) {
			logger.info("response header:" + getRespHeaderStr(response));
		}
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return getResponse(location, ua, refer);
		} else if (statusCode == 200) {
			return response;
		} else {
			logger.error(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		logger.error(e);
		return null;
	} finally {
	}
}
 
Example #29
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public byte[] postBytes(String url, Map<String, Object> list, String ua, String refer) {
	logger.info("postBytes=" + url);

	try {
		HttpResponse response = addHeader(HttpRequest.post(url).form(list).header(Header.USER_AGENT, ua)
				.header(Header.ACCEPT, _accept).header(Header.ACCEPT_ENCODING, _accept_encoding)
				.header(Header.REFERER, refer != null ? refer : url)
				.header(Header.ACCEPT_LANGUAGE, _accept_language).timeout(_time_out)).execute();

		if (debug) {
			logger.info("response header:" + getRespHeaderStr(response));
		}
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return postBytes(location, list, ua, refer);
		} else if (statusCode == 200) {
			return response.bodyBytes();
		} else {
			logger.error(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		logger.error(e);
		return null;
	} finally {
	}
}
 
Example #30
Source File: WebUtils.java    From tools-ocr with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String getHtml(String url) {
    HttpResponse response = get(url);
    String html = getSafeHtml(response);
    if (response != null) {
        response.close();
    }
    return html;
}