2011-03-31 2 views
0

내가 서버에 데이터를 게시하고 그리고 난 나는에포스트 방법의 응답

PostMethod post = new PostMethod(this._serverUrl); 

     InputStream is=null; 
     is = new ByteArrayInputStream(postData.getBytes("UTF-8")); 

     post.setRequestEntity(new InputStreamRequestEntity(is)); 
     post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1"); 

     HttpClient httpclient = new HttpClient(); 

     int result = httpclient.executeMethod(post); 

     String response=""; 
     response = post.getResponseBodyAsString(); 

내가 사용하고 공유지는 아파치이 코드 HttpClient를를 사용 ... 응답의 형태로 다시 포스트 데이터를 얻을 구문 분석 어떻게 게시 .... 여기에 내가

03-31 17:53:49.192: INFO/Response(2237): <?xml version="1.0" encoding="UTF-8"?> 
03-31 17:53:49.192: INFO/Response(2237): <AndroidGame> 
03-31 17:53:49.192: INFO/Response(2237): <Result>0</Result> 
03-31 17:53:49.192: INFO/Response(2237): <ErrorCode>509</ErrorCode> 
03-31 17:53:49.192: INFO/Response(2237): <ErrorMsg>You are using wrong Super Password</ErrorMsg> 
03-31 17:53:49.192: INFO/Response(2237): </AndroidGame> 

같은 응답을 얻을하지만 문자열의 응답을 얻을 필요가 .... 나는 온다 ... 단일 문자열에서 응답을 얻을 수 아니다 덩어리 ... 아무도이 날 도와 줄 수

답변

1

나는 (필자는 조금 지저분한 될 수 난 그렇게 사용하는 다른 방법의 코드를 연합) 이런 식으로 수행

HttpPost request = new HttpPost(url); 
    List<NameValuePair> postParameters = new ArrayList<NameValuePair>(); 
    postParameters.add(new BasicNameValuePair(PARAMETER_LOGIN, login)); 
    postParameters.add(new BasicNameValuePair(PARAMETER_PASSWORD, password)); 
    UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters, "UTF-8"); 
    request.setEntity(formEntity); 

    HttpResponse response = client.execute(request); 

    BufferedReader in = null; 
    try { 
     //Log.d("status line ", "test " + response.getStatusLine().toString()); 
     in = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); 
     StringBuffer sb = new StringBuffer(""); 
     String line = ""; 
     String NL = System.getProperty("line.separator"); 
     while ((line = in.readLine()) != null) { 
      sb.append(line + NL); 
     } 
     in.close(); 
     return sb.toString();  
    } finally { 
     if (in != null) { 
      try { 
       in.close(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
+0

안녕 맥심 ... : u는이 HttpResponse에 응답에 사용되는 어떤 클라이언트 D ... = client.execute (request); 당신은 지정할 수 있습니까? ... –

+0

HttpClient client = new DefaultHttpClient(); – Maxim