[HTML] REST or RESTful 이 뭔가요? ( Representational state transfer )
[android/안드로이드] Restful Get sample code.
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost( url );
// Parameters setting.
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add( new BasicNameValuePair( key1, value1 ) );
nameValuePairs.add( new BasicNameValuePair( key2, value2 ) );
try{
httpPost.setEntity( new UrlEncodedFormEntity( nameValuePairs ) );
HttpResponse httpResponse = httpClient.execute( httpPost );
HttpEntity entity = httpResponse.getEntity();
if ( entity != null ){
InputStream ins = entity.getContent();
String result = convertStreamToString( ins );
try {
ins.close();
} catch (IOException e) {
e.printStackTrace();
}
JSONObject json = new JSONObject( result );
try{
return json.getString( KEY_ID );
}
catch( Exception e ){
e.printStackTrace();
}
}
}
catch( Exception e ){
e.printStackTrace();
}
return null;
private static String convertStreamToString( InputStream ins ){
BufferedReader reader = new BufferedReader( new InputStreamReader( ins ) );
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}'프로그래밍 놀이터 > 안드로이드, Java' 카테고리의 다른 글
[android/안드로이드] gallery를 통해 pick& crop 동시에 하는 intent 생성. (0) | 2012.10.04 |
---|---|
[android/안드로이드] string xml에 white space넣는 방법 (2) | 2012.10.04 |
[android/안드로이드] activity manifest의 noHistory option code 로 구현하기 (0) | 2012.10.04 |
[Java] 병렬 프로그래밍 - 중단 및 종료 (0) | 2012.08.07 |
[Java] 병렬 프로그래밍 - 작업 실행 (0) | 2012.08.07 |
댓글