2011-10-07 42 views
0

我正在開發一個應用程序,我必須從服務器獲取響應。任何人都可以請分享,我可以打印從服務器端的響應代碼..任何幫助將不勝感激.. 謝謝..從服務器端的打印回覆android

+0

你想從一個網址 – surendra

+0

獲取數據接受的答案,然後它會幫助其他 – surendra

回答

2

意味着你有外部URL:「......」

你的要求該網址,你會得到什麼好嗎?

所以嘗試:

try { 

      String req = "your requst"; 

      String url = URL+ "?req="+req; 

      httpPost = new HttpPost(url); 
      HttpResponse httpResponse = httpclient.execute(httpPost); 
      int statuscode = httpResponse.getStatusLine().getStatusCode(); 
      if (statuscode == 200) { 
       String responseMsg = getResponse(httpResponse); 

       **System.out.println("Responce = "+responseMsg);** 
       return responseMsg; 
      }else{ 
       Log.e(TAG, statuscode+""); 
      } 
     } catch (ClientProtocolException e) { 
      Log.e(TAG, e.getMessage(),e); 
     } 
+0

+1幫助... – Aditya1510

1

如果你想從一個網址,以獲取數據,然後使用此代碼

static String page; 
public static String getValuefromUrl(String url){ 
try{ 
DefaultHttpClient httpClient = new DefaultHttpClient(); 
HttpGet httpGet = new HttpGet(url); 
ResponseHandler<String> resHandler = new BasicResponseHandler(); 
page = httpClient.execute(httpGet, resHandler); 
return page; 
} 
catch(Exception ex){ 
return page;  
} 
} 
+0

+1幫助n謝謝surendra ... – Aditya1510