Im using HttpCLient to autoLogin a website. I an getting statusCode as ‘200’. API says SC 200 – OK. what does that mean? Login is established?
When I see the list of statusCodes there is SC Accepted – 202. What is the difference between Accepted and OK.
If login is established what status code should I get? Please help.
pesudo code if this helps to answer:
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
public class HttpTest {
public static void main(String args[]) throws HttpException, IOException {
HttpClient client = new HttpClient();
// make the initial get to get the SESSION cookie
GetMethod get = new GetMethod(
"http://www.yahoo.com/");
client.executeMethod(get);
get.releaseConnection();
// authorize
PostMethod post = new PostMethod(
"https://login.yahoo.com/config/login?");
NameValuePair[] data = {
new NameValuePair("login", "aaa@yahoo.com"),
new NameValuePair("passwd", "bbb")
};
post.setRequestBody(data);
client.executeMethod(post);
post.releaseConnection();
//resubmit the original request
client.executeMethod(get);
String response = get.getResponseBodyAsString();
get.releaseConnection();
System.out.println("Status Code :::"+get.getStatusCode());
System.out.println(response);
}
}
This is the form based authentication i hvae been trying. I am getting the same issue here…200-ok for improper credentials. Im using a common website like yahoo to login. Any advice?
Java’s HttpClient status codes are the same as the status codes defined in RFC1945 (HTTP 1.0), RFC2616 (HTTP 2.0) and RFC2618 (WebDAV).
These specific codes mean:
200 OK
The request has succeeded. The information returned with the response is dependent on the method used in the request, for example:
GET an entity corresponding to the requested resource is sent in the response;
HEAD the entity-header fields corresponding to the requested resource are sent in the response without any message-body;
POST an entity describing or containing the result of the action;
TRACE an entity containing the request message as received by the end server.
202 Accepted
The request has been accepted for processing, but the processing has not been completed. The request might or might not eventually be acted upon, as it might be disallowed when processing actually takes place. There is no facility for re-sending a status code from an asynchronous operation such as this.
The 202 response is intentionally non-committal. Its purpose is to allow a server to accept a request for some other process (perhaps a batch-oriented process that is only run once per day) without requiring that the user agent’s connection to the server persist until the process is completed. The entity returned with this response SHOULD include an indication of the request’s current status and either a pointer to a status monitor or some estimate of when the user can expect the request to be fulfilled.
For definitions of the other common HTTP status codes, see RFC2616