2012-11-01 60 views
0

我有一個web服務,我想知道它是否是空的? 我想辦法做到這一點..如何發送請求並在textView中打印響應? 我知道要使用HttpConnetion 但我很困惑這個班!檢查webservice是否空

+0

返回true? getAttributeCount返回一個int! – Simon

+0

雅我知道,但我使用了一個條件,如果返回0 setText真 – user1767371

+0

getPropertyCount()呢? – mihail

回答

0

DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet httpPost = new HttpGet(urlName);

 HttpResponse httpResponse = httpClient.execute(httpPost); 
     HttpEntity httpEntity = httpResponse.getEntity(); 
     inputStream = httpEntity.getContent(); 




     BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8); 
     StringBuilder stringBuilder = new StringBuilder(); 
     String line = null; 
     if ((line = reader.readLine()) != null) { 
     stringBuilder.append(line + "\n"); 
     Data.servContent=stringBuilder.toString(); 
     } 

     line = reader.readLine(); 
     inputStream.close(); 
     } catch (UnsupportedEncodingException e) { 
      System.err.print("UnsupportedEncodingException: " + e); 
     } catch (ClientProtocolException e) { 
     System.err.print("ClientProtocolException: " + e); 
     } catch (IOException e) { 
     System.err.print("IOException: " + e); 
     } catch (Exception e) { 
     Log.e("Buffer Error", "Error converting result " + e.toString()); 
     }