这是我的代码。我收到HTTP / 1.1 400 Bad Request。不知道我在这里做错了什么。
try {
//client = new DefaultHttpClient();
client=HttpClientBuilder.create().build();
get = new HttpGet(queryURL.toString());
HttpResponse response = client.execute(get);
if(HttpStatus.SC_OK!=response.getStatusLine().getStatusCode()) {
throw new ServiceException(this, response.getStatusLine().getStatusCode()+"", response.getStatusLine().toString());
}
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
StringBuffer json = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
json.append(line);
}
错误消息。
ServiceException:HTTP / 1.1 400 Bad Request
答案 0 :(得分:0)
首先要查明Bad Request
的原因,您应该看到响应文字。您可以写如下:
client=HttpClientBuilder.create().build();
get = new HttpGet(queryURL.toString());
HttpResponse response = client.execute(get);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
StringBuilder responseAsString = new StringBuilder();
String line = "";
while ((line = rd.readLine()) != null) {
responseAsString.append(line);
}
if(HttpStatus.SC_OK!=response.getStatusLine().getStatusCode()) {
throw new ServiceException(this, response.getStatusLine().getStatusCode()+"", response.getStatusLine().toString() + ", cause: " + responseAsString);
}