Skip to content

Commit

Permalink
httpclient请求错误时,把请求url也打印出来
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix committed Jul 16, 2015
1 parent 365965f commit 298fcd0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/java/edu/scup/io/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class HttpClient {
private static final Logger logger = LoggerFactory.getLogger(HttpClient.class);
public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.13 Safari/537.36";
public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36";
private static final ObjectMapper objectMapper = new ObjectMapper();
public static Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 1080));
public static boolean useProxy;
Expand Down Expand Up @@ -66,7 +66,7 @@ public static String post(String url, byte[] body, String contentType) throws IO
conn.getOutputStream().write(body);

if (conn.getResponseCode() != 200) {
logger.error("response error {},request {}", IOUtils.toString(conn.getErrorStream()), new String(body));
logger.error("response error {},request url {},body {}", IOUtils.toString(conn.getErrorStream()), url, new String(body));
return "";
}

Expand Down Expand Up @@ -100,7 +100,8 @@ public static String postJSON(String url, Object request, Map<String, String> he
conn.getOutputStream().write(objectMapper.writeValueAsBytes(request));

if (conn.getResponseCode() != 200) {
logger.error("response error {},request {}", IOUtils.toString(conn.getErrorStream()), objectMapper.writeValueAsString(request));
logger.error("response error {},request url {},body {}", IOUtils.toString(conn.getErrorStream()), url
, objectMapper.writeValueAsString(request));
return "";
}

Expand Down

0 comments on commit 298fcd0

Please sign in to comment.