java-curl
java-curl copied to clipboard
getHttpCode() does not return the real HTTP code?
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);
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.