Skip to content

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

@RedSquirrel87

Description

@RedSquirrel87

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions