use of cn.hutool.http.HttpResponse in project hutool by looly.
the class HttpRequestTest method asyncHeadTest.
@Test
@Ignore
public void asyncHeadTest() {
HttpResponse response = HttpRequest.head(url).execute();
Map<String, List<String>> headers = response.headers();
Console.log(headers);
Console.log(response.body());
}
use of cn.hutool.http.HttpResponse in project hutool by looly.
the class HttpRequestTest method uploadTest.
@Test
@Ignore
public void uploadTest() {
File file = FileUtil.file("D:\\face.jpg");
// 方法一:自定义构建表单
HttpRequest request = //
HttpRequest.post(//
"http://localhost:8080/file/upload").form("file", //
file).form("fileType", "图片");
HttpResponse response = request.execute();
System.out.println(response.body());
}
use of cn.hutool.http.HttpResponse in project hutool by looly.
the class HttpRequestTest method asyncGetTest.
@Test
@Ignore
public void asyncGetTest() {
TimeInterval timer = DateUtil.timer();
HttpResponse body = HttpRequest.get(url).charset("GBK").executeAsync();
long interval = timer.interval();
timer.restart();
Console.log(body.body());
long interval2 = timer.interval();
Console.log("Async response spend {}ms, body spend {}ms", interval, interval2);
}
use of cn.hutool.http.HttpResponse in project hutool by looly.
the class SoapClient method sendForMessage.
/**
* 执行Webservice请求,即发送SOAP内容
*
* @return 返回结果
*/
public SOAPMessage sendForMessage() {
final HttpResponse res = sendForResponse();
final MimeHeaders headers = new MimeHeaders();
for (Entry<String, List<String>> entry : res.headers().entrySet()) {
if (StrUtil.isNotEmpty(entry.getKey())) {
headers.setHeader(entry.getKey(), CollUtil.get(entry.getValue(), 0));
}
}
try {
return this.factory.createMessage(headers, res.bodyStream());
} catch (IOException | SOAPException e) {
throw new SoapRuntimeException(e);
} finally {
IoUtil.close(res);
}
}
use of cn.hutool.http.HttpResponse in project Jpom by dromara.
the class TomcatManageService method tomcatCmd.
/**
* 访问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;
}
Aggregations