그러냐

안드로이드 service에서 포스트로 데이터 주고 받기 httppost 통신 본문

android

안드로이드 service에서 포스트로 데이터 주고 받기 httppost 통신

관절분리 2016. 1. 28. 10:58
반응형

public void postData() {

     try {
      httppost = new HttpPost(URL+"/lginsert.php?req=lgins&hpnum="+PhoneNumber+"&bcname="+bcname);
      response = httpclient.execute(httppost);
         bufreader = new BufferedReader(
     new InputStreamReader(response.getEntity().getContent(),
       "utf-8"));
         line = null;
   result = "";
   
   while ((line = bufreader.readLine()) != null) {
    result += line;
   }
   Log.d("22", result);

   
   
  } catch (Exception e) {
          // TODO Auto-generated catch block
     }
    
     
 }

 

 

//// 스레드로 접근 ////

 

new Thread(new Runnable() {           
            public void run() {       
                int i = 0;
                while (true) {
                    if(httpflag){
                     
                     postData();
                     httpflag = false;
                     
                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException ie) {
                            ie.printStackTrace();
                        }
                    }   
                                       
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException ie) {
                        ie.printStackTrace();
                    }
                }
            }
        }).start();    

 

반응형