2012-10-26 6 views

답변

1

,

 String input = String.format("<Request><Data><Id>%s</Id></Data> 
     </Request>",studentIdSelected); 

그런 다음 매개 변수로 입력 및 URL이 메소드를 호출

 public static String retriver(String Url, String input) { 

    String responseString = null; 
    StringEntity stringEntity; 
    HttpPost postRequest = new HttpPost(Url); 
    try { 

     Log.e("string is", input + "\n" + Url); 
     stringEntity = new StringEntity(input, "UTF-8"); 
     stringEntity.setContentType("application/atom+xml"); 

     postRequest.setEntity(stringEntity); 
     Log.v("Post", "Posted"); 
     HttpClient httpclient = new DefaultHttpClient(); 
     HttpResponse response = httpclient.execute(postRequest); 
     HttpEntity getResponseEntity = response.getEntity(); 

     responseString = EntityUtils.toString(getResponseEntity); 

    } catch (Exception e) { 
     // TODO: handle exception 
     postRequest.abort(); 
     Log.w("HttpPostRetreiver", "Error for URL " + Url, e); 
    } 

    return responseString; 

} 

또는 json도 사용할 수 있습니다.

+0

이 솔루션의 Thx이지만 JSONObject 및 JSONArray coz server requaied json 형식을 사용합니다. Soz를 위해 나는 전에 이것을 말하지 않았다 : / –

1

최상의 솔루션은 json 또는 xml 형식의 http 게시 요청을 보내는 것입니다.

당신은 각각 갖는 2 개 개의 필드는 다음 예를 들어, 같은 문자열로 을 그 변환 객체의 배열, 즉 당신의 구조 인 XML을 할 수
+0

나는 당신이 옳다고 믿지만, 나는 args를 URL에 넣어야한다. 어쨌든, 지금은 JSONObject 및 JSONArray 클래스를 사용하여 필요한 것을 수행하려고합니다. 나는 누군가가 시도한다면 이것이 좋은 해결책이 될 수 있다고 생각한다. –

+0

글쎄, 노력했다. 좋은 해결책이지만 '['또는 ','와 같은 특수 문자를 인코딩해야합니다. Base64에서 모든 것을 인코딩 한 다음 URL에 정말 긴 매개 변수를 넣습니다. 그것은 작동합니다. P –