문제

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?

도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top