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

getHttpCode() does not return the real HTTP code? #27

Open
RedSquirrel87 opened this issue Jun 6, 2023 · 1 comment
Open

getHttpCode() does not return the real HTTP code? #27

RedSquirrel87 opened this issue Jun 6, 2023 · 1 comment

Comments

@RedSquirrel87
Copy link

RedSquirrel87 commented Jun 6, 2023

I don't know if this is a bug or the expected behavior, but the curl.getHttpCode() function does not seem to work as intended by the name. It returns 200 for a successfully request and it's ok, but for example when you get a HTTP 403 Forbidden error it simply return -1 and not 403. Same thing for the 404 missing page error, it always returns -1.
Is there any way to get the "real" http code returned by the request?

If it can help this is the code I'm using:

URI uri = new URI(url);
Map<String, String> fakeHeaders = new HashMap<String, String>();
fakeHeaders.put("User-Agent", ua);
CUrl curl = new CUrl(uri.toASCIIString())
        .timeout(this.timeout, this.rtimeout)
        .headers(fakeHeaders)
        .cookieJar("cookie.jar")
        .location()
        .insecure();
curl.exec("UTF-8");
int r = curl.getHttpCode();
System.out.println("HTTP response code: " + r);
@rockswang
Copy link
Owner

Sorry I no longer maintain this project.
I suggest you try debugging the source code to see why the httpcode variable is not being assigned correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants