All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cz.jiripinkas.jsitemapgenerator.HttpClient Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 4.5
Show newest version
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();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy