0

I am trying to make a Http request in java, which seemed to work perfectly fine but suddenly the code broke with the error java.io.IOException: HTTP/1.1 header parser received no bytes

what should I change to get this to work? I am using the following code:

public static String request(int requestcode) throws URISyntaxException, IOException, InterruptedException{
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(new URI("http://localhost:8000/get"))
            .header("code", Integer.toString(requestcode))
            .GET()
            .build();

        HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
        return response.body();
    }

0 Answers0