[英]How to get response parameter in HttpClient
我正在尝试在一个应用程序中传递一些数据并从中获取响应。 为此,我正在使用 HttpClient 并希望在我的应用程序中使用 response 的值。 它可以是字符串、整数或 boolean
我写了以下代码
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);
}
此链接将返回参数 login=true/false。 现在如何使用响应获取登录参数的值?
请求中存储的所有属性都是字符串。 您将必须手动将其转换为任何类型。
例如,您尝试从请求中获取布尔值属性。 您将必须执行以下操作:
String attr = request.getAttribute("nameOfAttribute");
Boolean bool = Boolean.getBoolean(attr);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.