GoodDay and BadDay

jjunda.egloos.com

포토로그 마이가든



http에 timeout 설정 Android

http를 통해서 정보를 읽어올려고하는데..

서버가 종료되어있을때 빠져나와야하기때문에..

timeout걸고.. 아무런 응답이 없으면 null을 리턴한다..


HttpClient client = null;

public ScheduleApi(Context c) {
  // TODO Auto-generated constructor stub
  mContext = c;
   final HttpParams params = new BasicHttpParams();
         HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
         HttpProtocolParams.setContentCharset(params, "UTF-8");
         final SchemeRegistry registry = new SchemeRegistry();
         registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 7001));
         final ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
         client = new DefaultHttpClient(manager, params);
         client.getParams().setParameter("http.protocol.expect-continue", false); 
         client.getParams().setParameter("http.connection.timeout", 3000); 
         client.getParams().setParameter("http.socket.timeout", 3000);

 } 


public String check_schedule_dt(){
  String responseString = null;
  try{
   
   String requestStr = String.format(http://wwww 파일주소..");
   HttpGet getMethod = new HttpGet(requestStr);
   
   HttpResponse response = client.execute(getMethod);
      HttpEntity resEntity = response.getEntity();
      if(resEntity != null){
       return EntityUtils.toString(resEntity);
      }else
       return null;
      
      }catch(Exception t){
      
  }
  return null;
 }


트랙백

이 글과 관련된 글 쓰기 (트랙백 보내기)
TrackbackURL : http://jjunda.egloos.com/tb/5081822 [도움말]



메모장

곧 봄이다.. 나른나른..

W 위젯