2013-04-01 4 views

답변

0

보십시오이는 날이

public HttpResponse request(String filePath, String url) { 

     HttpClient httpclient = new DefaultHttpClient(); 
     httpclient.getParams() 
      .setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); 

     HttpPost httppost = new HttpPost(url); 
     MultipartEntity mpEntity = new MultipartEntity(); 




     File file = new File(filePath); 
     ContentBody cbFile = new FileBody(file, "image/png"); 
     mpEntity.addPart(PARAMETER_SIGNATURE, cbFile); 

     try { 

     httppost.setEntity(mpEntity); 
     System.out.println("executing request " + httppost.getRequestLine()); 
     HttpResponse response; 
     response = httpclient.execute(httppost); 
     httpclient.getConnectionManager().shutdown(); 
     return response; 
     } catch (Exception e) { 
     e.printStackTrace(); 
     } 
     return null; 
    } 

AsyncTask를 클래스

public class Task extends AsyncTask<String, Void, HttpResponse> { 

     private Exception exception; 


     protected void onPostExecute(HttpResponse response) { 
     Log.i("Loader ", response.getStatusLine().toString()); 
     // if (resEntity != null) { 
     // System.out.println(EntityUtils.toString(resEntity)); 
     // } 

     int status = response.getStatusLine().getStatusCode(); 
     if (status == 200) { 
      Log.i("Loader ", "upload ok"); 
     } else { 
      Log.i("Loader ", "upload failed"); 
     } 

     } 

     @Override 
     protected HttpResponse doInBackground(String... params) { 
     try { 

      return request(params[0], params[1]); 
     } catch (Exception e) { 
      this.exception = e; 
      return null; 
     } 
     } 

     public Exception getException() { 
     return exception; 
     } 
    } 
당신을 위해 작동 여부 알려
관련 문제