[英]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.