WeixinResponse构造器调整
This commit is contained in:
parent
bb18b98538
commit
8de4f4414d
@ -105,6 +105,7 @@ public class SimpleHttpClient extends AbstractHttpClient implements HttpClient {
|
||||
HttpHeaders headers = request.getHeaders();
|
||||
if (headers == null) {
|
||||
headers = new HttpHeaders();
|
||||
}
|
||||
if (!headers.containsKey(HttpHeaders.HOST)) {
|
||||
headers.set(HttpHeaders.HOST, request.getURI().getHost());
|
||||
}
|
||||
@ -116,7 +117,6 @@ public class SimpleHttpClient extends AbstractHttpClient implements HttpClient {
|
||||
if (!headers.containsKey(HttpHeaders.USER_AGENT)) {
|
||||
headers.set(HttpHeaders.USER_AGENT, "jdk/httpclient");
|
||||
}
|
||||
}
|
||||
for (Iterator<Entry<String, List<String>>> headerIterator = headers
|
||||
.entrySet().iterator(); headerIterator.hasNext();) {
|
||||
Entry<String, List<String>> header = headerIterator.next();
|
||||
|
||||
@ -12,7 +12,6 @@ import com.foxinmy.weixin4j.http.HttpMethod;
|
||||
import com.foxinmy.weixin4j.http.HttpParams;
|
||||
import com.foxinmy.weixin4j.http.HttpRequest;
|
||||
import com.foxinmy.weixin4j.http.HttpResponse;
|
||||
import com.foxinmy.weixin4j.http.HttpStatus;
|
||||
import com.foxinmy.weixin4j.http.apache.FormBodyPart;
|
||||
import com.foxinmy.weixin4j.http.apache.HttpMultipartMode;
|
||||
import com.foxinmy.weixin4j.http.apache.MultipartEntity;
|
||||
@ -97,10 +96,8 @@ public class WeixinRequestExecutor {
|
||||
request.setParams(params);
|
||||
try {
|
||||
HttpResponse httpResponse = httpClient.execute(request);
|
||||
HttpStatus status = httpResponse.getStatus();
|
||||
HttpHeaders headers = httpResponse.getHeaders();
|
||||
WeixinResponse response = new WeixinResponse(headers, status,
|
||||
httpResponse.getBody());
|
||||
WeixinResponse response = new WeixinResponse(httpResponse);
|
||||
String contentType = headers.getFirst(HttpHeaders.CONTENT_TYPE);
|
||||
String disposition = headers
|
||||
.getFirst(HttpHeaders.CONTENT_DISPOSITION);
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
package com.foxinmy.weixin4j.http.weixin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.foxinmy.weixin4j.http.HttpHeaders;
|
||||
import com.foxinmy.weixin4j.http.HttpResponse;
|
||||
import com.foxinmy.weixin4j.http.HttpStatus;
|
||||
import com.foxinmy.weixin4j.util.IOUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
@ -18,15 +17,10 @@ public class WeixinResponse {
|
||||
private boolean isXmlResult;
|
||||
private volatile String text;
|
||||
|
||||
private final HttpHeaders headers;
|
||||
private final HttpStatus status;
|
||||
private final InputStream body;
|
||||
private final HttpResponse response;
|
||||
|
||||
public WeixinResponse(HttpHeaders headers, HttpStatus status,
|
||||
InputStream body) {
|
||||
this.headers = headers;
|
||||
this.status = status;
|
||||
this.body = body;
|
||||
public WeixinResponse(HttpResponse response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public void setJsonResult(boolean isJsonResult) {
|
||||
@ -39,12 +33,7 @@ public class WeixinResponse {
|
||||
|
||||
public String getAsString() {
|
||||
if (text == null) {
|
||||
try {
|
||||
text = StringUtil.newStringUtf8(IOUtil.toByteArray(body));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
;
|
||||
}
|
||||
text = StringUtil.newStringUtf8(response.getContent());
|
||||
}
|
||||
return text;
|
||||
}
|
||||
@ -78,14 +67,14 @@ public class WeixinResponse {
|
||||
}
|
||||
|
||||
public HttpHeaders getHeaders() {
|
||||
return headers;
|
||||
return response.getHeaders();
|
||||
}
|
||||
|
||||
public HttpStatus getStatus() {
|
||||
return status;
|
||||
return response.getStatus();
|
||||
}
|
||||
|
||||
public InputStream getBody() {
|
||||
return body;
|
||||
return response.getBody();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user