Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returns 403 when it should 200 #1969

Closed
tjcoder opened this issue Jun 12, 2023 · 1 comment
Closed

Returns 403 when it should 200 #1969

tjcoder opened this issue Jun 12, 2023 · 1 comment
Labels
duplicate This is a duplicate issue or root-cause of another issue fixed

Comments

@tjcoder
Copy link

tjcoder commented Jun 12, 2023

var url = "https://www.elfcosmetics.com/brow-comb-+-brush/1807.html";
var response = Jsoup.connect(url);

This returns the 403 error code.

but this works:

var connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("User-Agent", USER_AGENT);

int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
    var content = new StringBuilder();
    try (var reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
        String line;
        while ((line = reader.readLine()) != null) {
            content.append(line);
        }
    }

    document = Jsoup.parse(content.toString());
}

connection.disconnect();

Jsoup version is 1.16.1

@jhy jhy added duplicate This is a duplicate issue or root-cause of another issue fixed labels Sep 8, 2023
@jhy
Copy link
Owner

jhy commented Sep 8, 2023

This was caused by incorrectly recoding the path, and is fixed in #1952.

@jhy jhy closed this as completed Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This is a duplicate issue or root-cause of another issue fixed
Projects
None yet
Development

No branches or pull requests

2 participants