mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix HttpClient lost body bug
This commit is contained in:
parent
bdf71b5e71
commit
5aed18a51b
@ -70,6 +70,6 @@ public class HttpClient4BodyEntity extends AbstractHttpEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getContentLength() {
|
public long getContentLength() {
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,9 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.http.client.engine.httpclient5;
|
package org.dromara.hutool.http.client.engine.httpclient5;
|
||||||
|
|
||||||
|
import org.apache.hc.core5.http.io.entity.AbstractHttpEntity;
|
||||||
import org.dromara.hutool.http.client.body.BytesBody;
|
import org.dromara.hutool.http.client.body.BytesBody;
|
||||||
import org.dromara.hutool.http.client.body.HttpBody;
|
import org.dromara.hutool.http.client.body.HttpBody;
|
||||||
import org.apache.hc.core5.http.io.entity.AbstractHttpEntity;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@ -67,6 +67,6 @@ public class HttpClient5BodyEntity extends AbstractHttpEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getContentLength() {
|
public long getContentLength() {
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.http;
|
package org.dromara.hutool.http;
|
||||||
|
|
||||||
|
import org.dromara.hutool.core.lang.Console;
|
||||||
import org.dromara.hutool.core.map.MapBuilder;
|
import org.dromara.hutool.core.map.MapBuilder;
|
||||||
import org.dromara.hutool.http.client.Request;
|
import org.dromara.hutool.http.client.Request;
|
||||||
import org.dromara.hutool.http.client.Response;
|
import org.dromara.hutool.http.client.Response;
|
||||||
@ -35,7 +36,9 @@ public class IssueI85C9STest {
|
|||||||
.form(MapBuilder.of("a", (Object)1).put("b", 2).build())
|
.form(MapBuilder.of("a", (Object)1).put("b", 2).build())
|
||||||
.send(engine);
|
.send(engine);
|
||||||
|
|
||||||
Assertions.assertEquals("{a=[1], b=[2]}", send.bodyStr());
|
final String bodyStr = send.bodyStr();
|
||||||
|
Console.log(bodyStr);
|
||||||
|
Assertions.assertEquals("{a=[1], b=[2]}", bodyStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023. looly(loolly@aliyun.com)
|
||||||
|
* Hutool is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* https://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.dromara.hutool.http.client;
|
||||||
|
|
||||||
|
import org.dromara.hutool.core.lang.Console;
|
||||||
|
import org.dromara.hutool.http.client.engine.httpclient5.HttpClient5Engine;
|
||||||
|
import org.dromara.hutool.http.meta.HeaderName;
|
||||||
|
import org.dromara.hutool.http.meta.Method;
|
||||||
|
import org.dromara.hutool.json.JSONUtil;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class XiaohonshuTest {
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
void postTest() {
|
||||||
|
long l = (new Date().getTime());
|
||||||
|
String sign = "oauth.getAccessToken?appId=880c43b57a97425d9a06×tamp="+l
|
||||||
|
+"&version=2.0d9758815286df7a3075d64785df2b890";
|
||||||
|
|
||||||
|
HashMap<String, Object> paramMap = new HashMap<>();
|
||||||
|
paramMap.put("sign",sign);
|
||||||
|
paramMap.put("appId", "880c43b57a97425d9a06"); //880c43b57a97425d9a06
|
||||||
|
paramMap.put("timestamp", l);
|
||||||
|
paramMap.put("version", "2.0");
|
||||||
|
paramMap.put("method", "oauth.getAccessToken");
|
||||||
|
paramMap.put("code", "code-266ef7f29fff4f0d80d4bd23f579391e-2097e077fad84eb0a5ec4a44a8de1116");
|
||||||
|
String json = JSONUtil.toJsonStr(paramMap);
|
||||||
|
|
||||||
|
Request request = Request.of("https://ark.xiaohongshu.com/ark/open_api/v3/common_controller")
|
||||||
|
.header(HeaderName.CONTENT_TYPE, "application/json;charset=UTF-8")
|
||||||
|
.method(Method.POST)
|
||||||
|
.body(json);
|
||||||
|
Console.log(request.send(new HttpClient5Engine()).bodyStr());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user