Kavin 02ca78ee7a
Manually close okhttp responses. (#210)
Ensure response is closed properly.
2022-03-03 12:27:43 +00:00

24 lines
634 B
Java

package me.kavin.piped.utils;
import me.kavin.piped.consts.Constants;
import okhttp3.Request;
import java.io.IOException;
public class RequestUtils {
public static String sendGet(String url) throws IOException {
return sendGet(url, Constants.USER_AGENT);
}
public static String sendGet(String url, String ua) throws IOException {
var request = new Request.Builder().header("User-Agent", ua).url(url).build();
var response = Constants.h2client.newCall(request).execute();
var responseString = response.body().string();
response.close();
return responseString;
}
}