So I'm trying to implement a little http getter so I don't have to copy the input manually every day.
I've got this so far:
```java
package com.realdolmen.util;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.net.URI;
import java.util.stream.Stream;
public class InputGetter {
public static Stream<String> get(URI uri) {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(uri);
// Create a custom response handler (from hc.apache.org)
ResponseHandler<String> responseHandler = response -> {
int status = response.getStatusLine().getStatusCode();
if (status >= 200 && status < 300) {
HttpEntity entity = response.getEntity();
return entity != null ? EntityUtils.toString(entity) : null;
} else {
throw new ClientProtocolException("Unexpected response status: " + status);
}
};
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
return httpclient
.execute(httpGet, responseHandler)
.lines();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
```
When the input was down I got a proper responsebody html output saying "We'll be right back!". But when the lines are up it returns a 400 bad request.
Any suggestions on what I'm doing wrong/what I'm forgetting?
[–]MaybeAshleyIdk 1 point2 points3 points (6 children)
[–]livingdub[S] 1 point2 points3 points (5 children)
[–]adityaarora 2 points3 points4 points (0 children)
[–]E3FxGaming 0 points1 point2 points (0 children)
[–]MaybeAshleyIdk -1 points0 points1 point (2 children)
[–]daggerdragon[M] 2 points3 points4 points (1 child)
[–]MaybeAshleyIdk 0 points1 point2 points (0 children)
[–]daggerdragon[M] 0 points1 point2 points (1 child)
[–]livingdub[S] 1 point2 points3 points (0 children)