|
16 | 16 |
|
17 | 17 | package com.xkcoding.http.support.httpclient; |
18 | 18 |
|
19 | | -import com.xkcoding.http.support.SimpleHttpResponse; |
20 | 19 | import com.xkcoding.http.config.HttpConfig; |
21 | 20 | import com.xkcoding.http.constants.Constants; |
22 | | -import com.xkcoding.http.exception.SimpleHttpException; |
23 | 21 | import com.xkcoding.http.support.AbstractHttp; |
24 | 22 | import com.xkcoding.http.support.HttpHeader; |
| 23 | +import com.xkcoding.http.support.SimpleHttpResponse; |
25 | 24 | import com.xkcoding.http.util.MapUtil; |
26 | 25 | import com.xkcoding.http.util.StringUtil; |
27 | 26 | import org.apache.http.Header; |
28 | | -import org.apache.http.HeaderElement; |
29 | 27 | import org.apache.http.HttpHost; |
30 | 28 | import org.apache.http.NameValuePair; |
31 | 29 | import org.apache.http.client.config.RequestConfig; |
|
40 | 38 | import org.apache.http.message.BasicNameValuePair; |
41 | 39 | import org.apache.http.util.EntityUtils; |
42 | 40 |
|
43 | | -import java.io.IOException; |
44 | 41 | import java.net.InetSocketAddress; |
45 | 42 | import java.net.Proxy; |
46 | 43 | import java.util.ArrayList; |
@@ -95,16 +92,16 @@ private SimpleHttpResponse exec(HttpRequestBase request) { |
95 | 92 | } |
96 | 93 |
|
97 | 94 | int code = response.getStatusLine().getStatusCode(); |
98 | | - boolean success = isSuccess(response); |
| 95 | + boolean successful = isSuccess(response); |
99 | 96 | Map<String, List<String>> headers = Arrays.stream(response.getAllHeaders()).collect(Collectors.toMap(Header::getName, (value) -> { |
100 | 97 | ArrayList<String> headerValue = new ArrayList<>(); |
101 | 98 | headerValue.add(value.getValue()); |
102 | 99 | return headerValue; |
103 | | - },(oldValue,newValue)->newValue)); |
104 | | - return new SimpleHttpResponse(success,code,headers, body.toString()); |
105 | | - } catch (IOException e) { |
| 100 | + }, (oldValue, newValue) -> newValue)); |
| 101 | + return new SimpleHttpResponse(successful, code, headers, body.toString(), null); |
| 102 | + } catch (Exception e) { |
106 | 103 | e.printStackTrace(); |
107 | | - return new SimpleHttpResponse(false,400,null,null); |
| 104 | + return new SimpleHttpResponse(false, 500, null, null, e.getMessage()); |
108 | 105 | } |
109 | 106 | } |
110 | 107 |
|
|
0 commit comments