2013-04-19 1 views
1

여기 httpPost() 자바 클래스, 또한 httpGet()을 숨기려면 httpPost()하는 방법?

public String getXmlFromUrl_NewRegistration(String url, 
     String username, String firstname, String lastname, String email, 
     String password) { 
    String json = null; 

    try { 
     // defaultHttpClient 

     DefaultHttpClient httpClient = new DefaultHttpClient(); 
     HttpPost httpPost = new HttpPost("http://aleedex.biz/game/users.php?action=new"); 
     String postParameter = "username=" + username + "&firstname=" 
       + firstname + "&lastname=" + lastname + "&email=" + email 
       + "&password=" + password; 

     try { 
      httpPost.setEntity(new StringEntity(postParameter)); 
     } catch (Exception e) { 

     } 

     HttpResponse httpResponse = httpClient.execute(httpPost); 
     HttpEntity httpEntity = httpResponse.getEntity(); 
     json = EntityUtils.toString(httpEntity); 

    } catch (UnsupportedEncodingException e) { 

    } catch (ClientProtocolException e) { 

    } catch (IOException e) { 

     json = null; 
    } 

    Log.d("json", json); 


    return json; 
} 

방법 httpGet을 통해 사용자를 등록하는 방법()에 동일한 매개 변수와 이름, 성, 이름, 이메일, 비밀번호 처럼 httpGet()에 동일한 매개 변수를 사용 그것은 당신이 URL에 POST 매개 변수를 추가하고 그것이

`HttpGet _getrequest=new HttpGet("http://aleedex.biz/game/users.php? action=new&"+postParameter); 

HttpResponse httpResponse = httpClient.execute(_getrequest); 
    HttpEntity httpEntity = httpResponse.getEntity(); 
    json = EntityUtils.toString(httpEntity);` 

이 시도하는 것이 작동하는 전화를 걸 수 있습니다 여기에 http://aleedex.biz/game/users.php?action=new

+0

아마 나쁜 관행이지만,가 HTTP 헤더에 모든 정보를 넣어 SSL이나 TLS를 사용하여 연결을 암호화 할 수 있습니다. –

+0

어떻게하면 http 헤더에 정보를 넣을 수 없습니까? –

+0

Google을 사용했습니다. http://stackoverflow.com/questions/12358045/java-httppost-request-with-apache-httpclient –

답변

0

링크 내가이 일을한다고 생각합니다.

+0

그게 나를 위해 도움이되지 않습니다 –

+0

정확히 U 원하는 HttpGet 요청 –

+0

예, 동일한 매개 변수를 간단하게 htttt 변경 httpget 어떻게 내가 어떻게합니까? –