Question

I am trying to pass some data in one application and get the response from that. For that I am using HttpClient and want to use the value of response in my application. It may be string, int, or boolean

I wrote the following code

HttpClient client = new DefaultHttpClient();

HttpPost request = new HttpPost(
    "http://index.html?email=" + email + 
    "&password=" + password
);

try {
    HttpResponse response = client.execute(request);
    HttpEntity entity = response.getEntity();
    InputStream is = entity.getContent();
    BufferedReader bf = new BufferedReader(
        new InputStreamReader(is,"UTF-8")
    );

    String str = bf.readLine();
        

} catch (Exception e) {
    System.out.println("Error is :- " + e);
}

This link will return parameter login=true/false. Now how can I get the value of the login parameter using response?

Was it helpful?

Solution

All attributes stored in the request are strings. You will have to manually cast it to whatever type they are.

For example you are trying to get a boolean attribute from the request. You will have to do this:

String attr = request.getAttribute("nameOfAttribute");
Boolean bool = Boolean.getBoolean(attr);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top