Example #1
0
    @Override
    protected Void doInBackground(Void... params) {
      String url = Constants.URL_REGISTER_PUSH + _id + "&provider=ANDROID";
      HttpEntity httpEntity = null;
      HttpClient client = new DefaultHttpClient();
      ServiceHandler sh = new ServiceHandler();
      try {
        client.getConnectionManager().getSchemeRegistry().register(sh.getMockedScheme());
      } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
      HttpGet method = new HttpGet(url);
      method.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
      method.setHeader("Authorization", token.getToken_type() + " " + token.getAccess_token());
      try {
        HttpResponse response = client.execute(method);
        httpEntity = response.getEntity();

      } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
      } catch (ClientProtocolException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return null;
    }
  public String uploadService(ArrayList<String> arrlink, TokenDTO token, String description) {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost postRequest = new HttpPost(Constants.URL_UPLOAD);

    postRequest.setHeader("Authorization", token.getToken_type() + " " + token.getAccess_token());
    HttpEntity httpEntity = null;
    try {
      MultipartEntity reqEntity = new MultipartEntity();
      reqEntity.addPart("Desc", new StringBody(description));
      reqEntity.addPart("CountryCode", new StringBody("1"));

      for (String pathImg : arrlink) {
        reqEntity.addPart("filename", new FileBody(new File(pathImg)));
      }

      postRequest.setEntity(reqEntity);

      HttpResponse response = httpclient.execute(postRequest);
      httpEntity = response.getEntity();
      responsecontent = EntityUtils.toString(httpEntity);

    } catch (Exception e) {
      // TODO: handle exception
    }
    return responsecontent;
  }