cz.jiripinkas.jsitemapgenerator.HttpClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsitemapgenerator Show documentation
Show all versions of jsitemapgenerator Show documentation
This library generates a web sitemap and can ping Google that it has changed. This project has been
inspired by sitemapgen4j, but is much more focused on traditional web sitemap and ease of use.
package cz.jiripinkas.jsitemapgenerator;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class HttpClient {
/**
* HTTP GET to URL, return status
*
* @param url URL
* @return status code (for example 200)
* @throws Exception When error
*/
public int get(String url) throws Exception {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.build();
try(Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new Exception("error sending HTTP GET to this URL: " + url);
}
return response.code();
}
}
}