3.9K Star 22.7K Fork 7.8K

GVPdromara / hutool

 / 详情

HttpRequest.post()请求接口表单参数带字符串和文件参数时,设置超时没有用,可能原因是什么?

已完成
创建于  
2024-05-10 11:05

版本情况

JDK版本: Oracle JDK 1.8
hutool版本: 5.7.17

问题描述(包括截图)

HttpRequest.post()请求第三方接口表单格式参数,参数包含字符串和文件时,设置超时没有用,到设定时间后并没有抛出异常,还是一直在等待响应,去掉文件参数可以正常抛出读取响应异常,不知道是什么原因?麻烦各位大神给指导一下,谢谢!
输入图片说明

  1. 复现代码
    File imageFile = FileUtil.file(".", imageUrl.substring(imageUrl.lastIndexOf('/') + 1));
    // 使用hutool的HttpUtil下载图片
    String response = HttpUtil.get(imageUrl);
    // 将响应内容写入文件
    FileUtil.writeBytes(response.getBytes(), imageFile);
    paramMap.put("file", imageFile);
    // 记录开始时间
    long startTime = 0;
    String result = "null";
    try {
    System.out.println("执行请求开始!!!!!!!!!!!!!!!");
    startTime = System.currentTimeMillis();
    // result = HttpUtil.post(url, paramMap, 10000);
    result = HttpRequest.post(url)
    .header("Content-Type", "multipart/form-data")
    .form(paramMap)
    .timeout(3000)
    .execute()
    .body();

  2. 堆栈信息
    输入图片说明

评论 (1)

梦羽 创建了任务

超时为连接和读取超时。

我猜测你参数有文件有上传文件的操作,这个写出到服务器的过程如果很慢则超时无效

这个在服务端设置,或者考虑HttpClient。

Looly 任务状态待办的 修改为已完成
Looly 添加了
 
question
标签

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
1463 loolly admin 1578914022
Java
1
https://gitee.com/dromara/hutool.git
git@gitee.com:dromara/hutool.git
dromara
hutool
hutool

搜索帮助

344bd9b3 5694891 D2dac590 5694891