|
5 | 5 | import com.baidubce.appbuilder.base.exception.AppBuilderServerException; |
6 | 6 | import com.baidubce.appbuilder.base.utils.iterator.StreamIterator; |
7 | 7 | import com.baidubce.appbuilder.base.utils.json.JsonUtils; |
8 | | - |
9 | | -import java.io.IOException; |
10 | | -import java.lang.reflect.Type; |
11 | | -import java.net.URLEncoder; |
12 | | -import java.util.Iterator; |
13 | | -import java.util.LinkedHashMap; |
14 | | -import java.util.Map; |
15 | | -import java.util.concurrent.TimeUnit; |
16 | | -import java.util.logging.ConsoleHandler; |
17 | | -import java.util.logging.Level; |
18 | | -import java.util.logging.FileHandler; |
19 | | -import java.util.logging.Logger; |
20 | | - |
| 8 | +import org.apache.hc.client5.http.classic.methods.HttpDelete; |
21 | 9 | import org.apache.hc.client5.http.classic.methods.HttpGet; |
22 | 10 | import org.apache.hc.client5.http.classic.methods.HttpPost; |
23 | | -import org.apache.hc.client5.http.classic.methods.HttpDelete; |
| 11 | +import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase; |
24 | 12 | import org.apache.hc.client5.http.config.RequestConfig; |
25 | 13 | import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; |
26 | 14 | import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; |
|
31 | 19 | import org.apache.hc.core5.http.ParseException; |
32 | 20 | import org.apache.hc.core5.http.io.entity.EntityUtils; |
33 | 21 |
|
| 22 | +import java.io.IOException; |
| 23 | +import java.lang.reflect.Type; |
| 24 | +import java.net.URLEncoder; |
| 25 | +import java.util.LinkedHashMap; |
| 26 | +import java.util.Map; |
| 27 | +import java.util.concurrent.TimeUnit; |
| 28 | +import java.util.logging.ConsoleHandler; |
| 29 | +import java.util.logging.FileHandler; |
| 30 | +import java.util.logging.Level; |
| 31 | +import java.util.logging.Logger; |
| 32 | + |
34 | 33 | public class HttpClient { |
35 | 34 | public String SecretKey; |
36 | 35 | public String Gateway; |
@@ -169,11 +168,11 @@ public ClassicHttpRequest createGetRequestV2(String url, Map<String, Object> map |
169 | 168 | return httpGet; |
170 | 169 | } |
171 | 170 |
|
172 | | - public ClassicHttpRequest createDeleteRequestV2(String url, Map<String, Object> map) { |
| 171 | + public ClassicHttpRequest createDeleteRequestV2(String url, Map<String, Object> map) { |
173 | 172 | // 处理查询参数 |
174 | 173 | String urlParams = toQueryString(map); |
175 | 174 | // 如果 URL 已经包含 '?', 不需要再添加 |
176 | | - String requestURL = GatewayV2 + ConsoleOpenAPIPrefix + ConsoleOpenAPIVersion + url |
| 175 | + String requestURL = GatewayV2 + ConsoleOpenAPIPrefix + ConsoleOpenAPIVersion + url |
177 | 176 | + (url.contains("?") ? "&" : "?") + urlParams; |
178 | 177 |
|
179 | 178 | LOGGER.log(Level.FINE, "requestURL: " + requestURL); |
@@ -222,10 +221,10 @@ public <T> HttpResponse<T> execute(ClassicHttpRequest request, Type bodyType) |
222 | 221 | }); |
223 | 222 | if (httpResponse.getCode() != 200) { |
224 | 223 | String errorMessage = String.format( |
225 | | - "Error after processing response with code %d for request ID: %s, message: %s", |
226 | | - httpResponse.getCode(), |
227 | | - httpResponse.getRequestId(), |
228 | | - httpResponse.getMessage() |
| 224 | + "Error after processing response with code %d for request ID: %s, message: %s", |
| 225 | + httpResponse.getCode(), |
| 226 | + httpResponse.getRequestId(), |
| 227 | + httpResponse.getMessage() |
229 | 228 | ); |
230 | 229 | LOGGER.log(Level.SEVERE, errorMessage); |
231 | 230 | throw new AppBuilderServerException(httpResponse.getRequestId(), httpResponse.getCode(), |
@@ -256,7 +255,7 @@ public <T> HttpResponse<StreamIterator<T>> executeSSE(ClassicHttpRequest request |
256 | 255 | } |
257 | 256 | return new HttpResponse<StreamIterator<T>>().setCode(resp.getCode()) |
258 | 257 | .setMessage(resp.getReasonPhrase()).setRequestId(requestId).setHeaders(headers) |
259 | | - .setBody(new StreamIterator<>(resp, bodyType)); |
| 258 | + .setBody(new StreamIterator<>(resp, bodyType, (HttpUriRequestBase) request)); |
260 | 259 | } |
261 | 260 |
|
262 | 261 | private String toQueryString(Map<String, Object> map) { |
|
0 commit comments