Home:ALL Converter>HttpClient statusCodes

HttpClient statusCodes

Ask Time:2012-01-07T04:29:28         Author:Geek

Json Formatter

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", "[email protected]"),
    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?

Author:Geek,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/8764065/httpclient-statuscodes
David Perry :

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).\n\nThese specific codes mean:\n\n200 OK\n\nThe request has succeeded. The information returned with the response is dependent on the method used in the request, for example:\n\nGET an entity corresponding to the requested resource is sent in the response;\n\nHEAD the entity-header fields corresponding to the requested resource are sent in the response without any message-body;\n\nPOST an entity describing or containing the result of the action;\n\nTRACE an entity containing the request message as received by the end server.\n\n202 Accepted\n\nThe 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.\n\nThe 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.\n\nFor definitions of the other common HTTP status codes, see RFC2616",
2012-01-06T20:36:14
David :

200 means the request was successful and the response is based on that successful request. 202 would mean that the request was successful and has been queued for processing on the server, so the response isn't based on successful completion of the request because it hasn't necessarily completed yet.\nThink of it like a short conversational exchange...\n200:\n\nClient: Here is my request\nServer: Thanks! I've processed your request. Here's the response you were looking for.\n\nvs.\n202:\n\nClient: Here is my request\nServer: Thanks! I'm not done processing it yet, but I'm just letting you know that I've received it and it's under way.\n\nI can't imagine a login taking a long time, so I'd expect a successful login to always return a 200 response.",
2012-01-06T20:35:14
kosa :

202 Accepted means, your request is getting processed by the receiver (something like I got your application will look into it).\n\n200 OK means, Your application was processed and granted what you requested (whether it could be login (or) request for another resource).",
2012-01-06T20:32:53
Freiheit :

Review this list: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes\n\nBut as milan stated you should review the API and make sure the API is using those error codes the same way the standard says to use them.\n\nFor example, you could try a login get a 200, but the payload returned has a login failure message.\n\nA better behaved implementation would return a 200 for a good login and a 401 or 403 on a bad login.",
2012-01-06T20:36:09
yy