【发布时间】:2021-01-28 21:04:30
【问题描述】:
我是第一次来
原因:java.io.IOException:HTTP/1.1 标头解析器未收到任何字节
(我的应用程序似乎可以运行到现在......)
HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest httpRequest = HttpRequest
.newBuilder()
.GET()
.uri(URI.create("..."))
.header("Content-Type", "application/json")
.build();
System.out.print(httpRequest.toString()); // dbg - it's ok
HttpResponse<String> response = null;
try {
response = httpClient.send(httpRequest,
HttpResponse.BodyHandlers.ofString());
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
if (response != null && response.statusCode() == 200) {
JSONObject jsonObject = new JSONObject(response.body());
JSONArray jsonArray = jsonObject.getJSONArray("data");
ObjectMapper objectMapper = ObjectMapperCreator.getNewObjectMapper();
try {
if (jsonArray.length() > 0) {
correctlyCaught = true;
return objectMapper.readValue(jsonArray.get(0).toString(), GeocodingResponse.class);
}
} catch (IOException e) {
e.printStackTrace();
}
}
这是代码。为什么会出现此错误?
【问题讨论】:
-
您有什么要求?你的请求头是空的吗?
标签: java ioexception