Beispiel #1
0
  // http://192.168.2.4:9000/imgupload/upload_image.php
  // http://192.168.2.4:9999/ImageUploadWebApp/uploadimg.jsp
  // Make Http call to upload Image to Php server
  public void makeHTTPCall() {
    AsyncHttpClient client = new AsyncHttpClient();
    client.setTimeout(60000);
    // Don't forget to change the IP address to your LAN address. Port no as well.
    String URL = "http://hosamazzam.0fees.net/Blog_db_online/";
    //     URL="http://10.0.3.2/Blog_db/";

    if (type == "user") {

      client.post(
          URL + "db_upload.php",
          params,
          new AsyncHttpResponseHandler() {
            // When the response returned by REST has Http
            // response code '200'
            @Override
            public void onSuccess(String response) {
              // Hide Progress Dialog
              up.finish_uploading();
              System.out.println(response);
            }

            @Override
            public void onFailure(Throwable error, String content) {
              super.onFailure(error, content);
              System.out.println(content);
              up.failed();
            }
          });
    } else {
      client.post(
          URL + "db_upload_post.php",
          params,
          new AsyncHttpResponseHandler() {
            // When the response returned by REST has Http
            // response code '200'
            @Override
            public void onSuccess(String response) {
              // Hide Progress Dialog
              post.finish_uploading();
              System.out.println(response);
            }

            @Override
            public void onFailure(Throwable error, String content) {
              super.onFailure(error, content);
              //   System.out.println(content);
              post.failed();
            }
          });
    }
  }
  private void getHomeData() {
    RequestParams params = RequestParam.getRequestParams(getActivity());
    params.put("pageCount", 20);
    client.post(
        HttpConfig.getGetHomelist(userId),
        params,
        new AsyncHttpResponseCallBack(getActivity()) {
          @Override
          public void onSuccess(int i, Header[] headers, byte[] bytes) {
            super.onSuccess(i, headers, bytes);
            try {
              Log.e("hot", new String(bytes));
              Type type = new TypeToken<HomeDataEntry>() {}.getType();
              homeData = gson.fromJson(new String(bytes), type);
              storeUrl = homeData.getData().getHost();
              SharedPreferenceUtil.getSharedEditor(getActivity())
                  .putString(SharedPreferenceUtil.HOST, storeUrl)
                  .commit();
              SharedPreferenceUtil.getSharedEditor(getActivity())
                  .putString(SharedPreferenceUtil.SEARCH_WORD, homeData.getData().getSearchWord())
                  .commit();
              FileUtil.writeData(FileUtil.TEXT_BACKUP, new String(bytes));
              hotWork = homeData.getData().getHotWorkTagList();
              mList.clear();
              mList.addAll(homeData.getData().getWorks().getWorks());
              handler.sendEmptyMessage(1);
            } catch (Exception e) {

            }
          }

          @Override
          public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {}
        });
  }
  public void startArmCallback(final String number) {
    Bundle extras = new Bundle();
    extras.putString(WebSendParam.phoneNumber.name(), number);
    //        SmartPagerApplication.getInstance().startWebAction(WebAction.armCallback, extras);
    ((BaseActivity) getActivity()).showProgressDialog(getString(R.string.sending_request));

    RequestParams params = new RequestParams();
    params.put("smartPagerID", SmartPagerApplication.getInstance().getPreferences().getUserID());
    params.put("uberPassword", SmartPagerApplication.getInstance().getPreferences().getPassword());
    params.put("phoneNumber", number);

    httpClient.post(
        getActivity().getApplicationContext(),
        Constants.BASE_REST_URL + "/armCallback",
        params,
        new JsonHttpResponseHandler() {

          @Override
          public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            System.out.println("successful response: " + response);
            ((BaseActivity) getActivity()).hideProgressDialog();
            makeArmCallBack(number);
          }

          @Override
          public void onFailure(
              int statusCode, Header[] headers, String responseBody, Throwable error) {
            System.out.println("failure response: " + responseBody);
            ((BaseActivity) getActivity()).hideProgressDialog();
          }
        });
  }
Beispiel #4
0
  public void menu_sendData(
      Context context, String name, String cafe_name, final OnResultListener<Boolean> listener) {
    String SERVER = AddressBean.Address + "/search_menu";
    RequestParams params = new RequestParams();
    params.put("Menu_Name", name);
    params.put("Cafe_Name", cafe_name);

    client.post(
        context,
        SERVER,
        params,
        new TextHttpResponseHandler() {

          @Override
          public void onFailure(
              int statusCode, Header[] headers, String responseString, Throwable throwable) {
            listener.onFail(statusCode);
          }

          @Override
          public void onSuccess(int statusCode, Header[] headers, String responseString) {
            Gson gson = new Gson();
            boolean result = gson.fromJson(responseString, boolean.class);
            listener.onSuccess(result);
          }
        });
  }
  public void clickGetAcc() {

    RequestParams params = new RequestParams();

    params.put("j_username", firstparameter.trim());
    params.put("j_password", secondparameter.trim());

    System.out.println(params.toString());

    httpClient.post(
        METRO_STEP2,
        params,
        new AsyncHttpResponseHandler() {
          @Override
          public void onSuccess(String response) {

            System.out.println("metrobank5 response " + response);
            // myProgressDialog.dismiss();
            clickJavier();
          }

          public void onFailure(Throwable error, String content) {
            System.out.println("metrobank2 e1rror  " + content);
            myProgressDialog.dismiss();
          }
        });
  }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    System.out.println(resultCode);
    System.out.println(BraintreePaymentActivity.RESULT_OK);
    if (resultCode == BraintreePaymentActivity.BRAINTREE_RESULT_DEVELOPER_ERROR) {
      System.out.println("test");

    } else if (resultCode == BraintreePaymentActivity.BRAINTREE_RESULT_SERVER_ERROR) {
      System.out.println("test2");
    }

    if (resultCode == BraintreePaymentActivity.RESULT_OK) {
      System.out.println("hello");
      String paymentMethodNonce =
          data.getStringExtra(BraintreePaymentActivity.EXTRA_PAYMENT_METHOD_NONCE);

      RequestParams requestParams = new RequestParams();
      requestParams.put("payment_method_nonce", paymentMethodNonce);
      requestParams.put("amount", "10.00");

      client.post(
          "https://pacific-tor-4300.herokuapp.com" + "/payment_methods",
          requestParams,
          new TextHttpResponseHandler() {
            @Override
            public void onSuccess(String content) {
              System.out.print("olala");
              Toast.makeText(SearchActivity.this, "You've just bought a credit!", Toast.LENGTH_LONG)
                  .show();
            }
          });
    }
  }
  public void invokeWS(StringEntity entity) {
    AsyncHttpClient client = new AsyncHttpClient();
    client.post(
        getApplicationContext(),
        "http://mudgea3.cloudapp.net:5000/api/audio/1",
        entity,
        "application/json",
        new JsonHttpResponseHandler() {
          @Override
          public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
              Log.v("status is", response.toString());

            } catch (Exception e) {
              Log.e("JSON error", "errror");
            }
          }

          @Override
          public void onFailure(
              int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            Log.e("REST CALL ERROR", "tried to send audio " + statusCode);
            Log.e("audio error", errorResponse.toString());
          }
        });
  }
 public void post(
     Context context,
     String str,
     RequestParams requestParams,
     AsyncHttpResponseHandler asyncHttpResponseHandler) {
   post(context, str, paramsToEntity(requestParams), null, asyncHttpResponseHandler);
 }
  /**
   * Performs a POST request to the Singly API.
   *
   * <p>All network communication is performed in a separate thread. As such it is fine to call this
   * method from the main UI thread.
   *
   * <p>The AsyncApiResponseHandler parameter is an asynchronous callback handler that is used to
   * retrieve the result of the network request to the API. On success the response from the API is
   * returned. On failure a Throwable error object will be returned.
   *
   * <p>If an API call requires an access token it must be added to the queryParams passed into the
   * method.
   *
   * @param context The current android context.
   * @param apiEndpoint The Singly API endpoint to call.
   * @param queryParams Any query parameters to send along with the request.
   * @param responseHandler An asynchronous callback handler for the request.
   * @see https://singly.com/docs/api For documentation on Singly api calls.
   * @see SinglyUtils#getAccessToken(Context)
   */
  public void doPostApiRequest(
      Context context,
      String apiEndpoint,
      Map<String, String> queryParams,
      final AsyncApiResponseHandler responseHandler) {

    // get the http client and add api url
    AsyncHttpClient client = new AsyncHttpClient();
    Map<String, String> params = new LinkedHashMap<String, String>();
    if (queryParams != null) {
      params.putAll(queryParams);
    }
    String postApiCallUrl = SinglyUtils.createSinglyURL(apiEndpoint);
    RequestParams rparms = params.isEmpty() ? null : new RequestParams(params);

    // do an async post request
    client.post(
        postApiCallUrl,
        rparms,
        new AsyncHttpResponseHandler() {

          @Override
          public void onSuccess(String response) {
            responseHandler.onSuccess(response);
          }

          @Override
          public void onFailure(Throwable error) {
            responseHandler.onFailure(error);
          }
        });
  }
  public void makeVoipCall(final String number) {
    AudioManagerUtils.setLoudSpeaker(false);
    ((BaseActivity) getActivity()).showProgressDialog("Connecting VOIP Call");
    RequestParams params = new RequestParams();
    params.put("smartPagerID", SmartPagerApplication.getInstance().getPreferences().getUserID());
    params.put("uberPassword", SmartPagerApplication.getInstance().getPreferences().getPassword());

    AsyncHttpClient httpClient = new AsyncHttpClient();
    httpClient.post(
        getActivity().getApplicationContext(),
        Constants.BASE_REST_URL + "/getTwilioClientToken",
        params,
        new JsonHttpResponseHandler() {

          @Override
          public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            System.out.println("successful response: " + response);
            ((BaseActivity) getActivity()).hideProgressDialog();

            VoipPhone voipPhone =
                new VoipPhone(
                    ((BaseActivity) getActivity()).getApplicationContext(),
                    response.optString("token"));
            voipPhone.connect(number);
          }

          @Override
          public void onFailure(
              int statusCode, Header[] headers, String responseBody, Throwable error) {
            System.out.println("failure response: " + responseBody);
            ((BaseActivity) getActivity()).hideProgressDialog();
          }
        });
  }
  private void sendInboxIgnore(String UID) {
    if (mAsyncHttpClient != null) {
      startProgressIndicator();
      mAsyncHttpClient.post(
          getActivity(),
          openHABBaseUrl + "rest/inbox/" + UID + "/ignore",
          null,
          "text/plain",
          new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
              stopProgressIndicator();
              Log.d(TAG, "Inbox ignore request success");
              refresh();
            }

            @Override
            public void onFailure(
                int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
              stopProgressIndicator();
              Log.e(TAG, "Inbox ignore request error: " + error.getMessage());
            }
          });
    }
  }
  /**
   * Performs a POST request to the Singly API that allows specifying the body content of the
   * request. This is used when you need to POST raw content, such as text or images, to the API.
   *
   * <p>Any query parameters passed are appended to the URL versus being passed in the body of the
   * POST request.
   *
   * <p>All network communication is performed in a separate thread. As such it is fine to call this
   * method from the main UI thread.
   *
   * <p>The AsyncApiResponseHandler parameter is an asynchronous callback handler that is used to
   * retrieve the result of the network request to the API. On success the response from the API is
   * returned. On failure a Throwable error object will be returned.
   *
   * <p>If an API call requires an access token it must be added to the queryParams passed into the
   * method.
   *
   * @param context The current android context.
   * @param apiEndpoint The Singly API endpoint to call.
   * @param queryParams Any query parameters to send along with the request.
   * @param body The content to use as the body of the request.
   * @param contentType The MIME content type being sent.
   * @param responseHandler An asynchronous callback handler for the request.
   * @see https://singly.com/docs/api For documentation on Singly api calls.
   * @see SinglyUtils#getAccessToken(Context)
   */
  public void doBodyApiRequest(
      Context context,
      String apiEndpoint,
      Map<String, String> queryParams,
      byte[] body,
      String contentType,
      final AsyncApiResponseHandler responseHandler) {

    // get the http client and add api url
    AsyncHttpClient client = new AsyncHttpClient();
    Map<String, String> params = new LinkedHashMap<String, String>();
    if (queryParams != null) {
      params.putAll(queryParams);
    }
    String postApiCallUrl = SinglyUtils.createSinglyURL(apiEndpoint, params);

    // do an async post request with the raw body content
    client.post(
        context,
        postApiCallUrl,
        new ByteArrayEntity(body),
        contentType,
        new AsyncHttpResponseHandler() {

          @Override
          public void onSuccess(String response) {
            responseHandler.onSuccess(response);
          }

          @Override
          public void onFailure(Throwable error) {
            responseHandler.onFailure(error);
          }
        });
  }
Beispiel #13
0
  private void getFriend() {
    AsyncHttpClient myClient;

    myClient = new AsyncHttpClient();
    myClient.setTimeout(SingleToneData.getInstance().getTimeOutValue());
    PersistentCookieStore myCookieStore = new PersistentCookieStore(context);
    myClient.setCookieStore(myCookieStore);

    String url = context.getString(R.string.url_gift_list);

    RequestParams params = new RequestParams();
    LoginUtils loginUtils = new LoginUtils(context);

    params.put("id", loginUtils.getId());
    params.put("pw", loginUtils.getPw());

    myClient.post(
        url,
        params,
        new AsyncHttpResponseHandler() {
          @Override
          public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
            Log.i("(friend fragment)", new String(responseBody));
            getGiftFinish(new String(responseBody));
          }

          @Override
          public void onFailure(
              int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
            Toast.makeText(
                    context, getResources().getString(R.string.on_failure), Toast.LENGTH_SHORT)
                .show();
          }
        });
  }
 /** 更改photo名字 */
 private void changelnfo() {
   AsyncHttpClient client = new AsyncHttpClient();
   RequestParams params = new RequestParams();
   params.put("Photo", photo);
   params.put("act", "updateinfo");
   params.put("ID", NApplication.userid);
   client.post(Url.userLogin, params, change_info_handler);
 }
  public void getDBSize() {
    AsyncHttpClient client = new AsyncHttpClient();
    RequestParams params = new RequestParams();
    params.put(Settings.DB_HOST, sharedPrefs.getValueStr(SharedPrefs.KEY_DB_HOST));
    params.put(Settings.DB_NAME, sharedPrefs.getValueStr(SharedPrefs.KEY_DB_NAME));
    params.put(Settings.DB_USER, sharedPrefs.getValueStr(SharedPrefs.KEY_DB_USERNAME));
    params.put(Settings.DB_PASSWORD, sharedPrefs.getValueStr(SharedPrefs.KEY_DB_PASSWORD));

    System.out.println("params: " + params.toString());

    String url = sharedPrefs.getValueStr(SharedPrefs.KEY_DOMAIN_NAME) + "/php/checkDBSize.php";
    Log.i("getDBSize", "URL: " + url);

    client.post(
        url,
        params,
        new AsyncHttpResponseHandler() {
          @Override
          public void onSuccess(String response) {
            System.out.println("sucess sa dbcheck");
            try {
              JSONObject json_data = new JSONObject(response);
              double size = (json_data.getDouble("size"));
              dataHandler.setDbSize(size);
              Log.i("checkDBSize", "DB Size: " + dataHandler.getDbSize());
              dialog.dismiss();
              updateDialog.dismiss();

              Intent intent = new Intent(getApplicationContext(), UpdateManager.class);
              startActivity(intent);

            } catch (Exception e) {
              updateDialog.dismiss();
              Log.e("Fail 3", e.toString());
            }
          }

          @Override
          public void onFailure(int statusCode, Throwable error, String content) {
            dialog.dismiss();
            System.out.println("failed sa dbcheck");
            if (statusCode == 404) {
              Log.e("getDBSize", "ERROR 404");
            } else if (statusCode == 500) {
              Log.e("getDBSize", "ERROR 500");
            } else {
              Log.e(
                  "getDBSize",
                  "ERROR OCCURED!  content: "
                      + content
                      + "\nstatus: "
                      + statusCode
                      + "\nerror: "
                      + error.toString());
            }
          }
        });
  }
 @Override
 public RequestHandle executeSample(
     AsyncHttpClient client,
     String URL,
     Header[] headers,
     HttpEntity entity,
     ResponseHandlerInterface responseHandler) {
   return client.post(this, URL, headers, entity, null, responseHandler);
 }
 /** 登录,获取用户信息 */
 private void userlnfo() {
   AsyncHttpClient client = new AsyncHttpClient();
   RequestParams params = new RequestParams();
   params.put("act", "login");
   params.put("phone", phone);
   params.put("pass", pass);
   params.put("equipment", NApplication.device_token);
   client.post(Url.userLogin, params, user_info_handler);
 }
 @Override
 public RequestHandle executeRequest(
     AsyncHttpClient client,
     String URL,
     Header[] headers,
     HttpEntity entity,
     ResponseHandlerInterface responseHandler) {
   return client.post(this, getDefaultURL(), mParams, responseHandler);
 }
  public void broadcastLocationFound(Location location) {

    String deviceId =
        Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);

    params = new RequestParams();
    params.put("UID", deviceId);
    params.put("LAT", Double.toString(location.getLatitude()));
    params.put("LON", Double.toString(location.getLongitude()));
    params.put("ACU", Double.toString(location.getAccuracy()));
    params.put("SPD", Double.toString(location.getSpeed()));

    PersistentCookieStore CookieStore = new PersistentCookieStore(LocationService.this);
    CookieStore.clear();
    AsyncHttpClient sendLocation = new AsyncHttpClient(false, 80, 443);
    sendLocation.setCookieStore(CookieStore);
    sendLocation.setTimeout(60000);
    sendLocation.post(
        url,
        params,
        new JsonHttpResponseHandler() {

          @Override
          public void onSuccess(
              int statusCode, cz.msebera.android.httpclient.Header[] headers, JSONObject response) {
            super.onSuccess(statusCode, headers, response);
            Log.i(TAG, response.toString());
          }

          @Override
          public void onSuccess(
              int statusCode, cz.msebera.android.httpclient.Header[] headers, JSONArray response) {
            super.onSuccess(statusCode, headers, response);
            Log.i(TAG, response.toString());
          }

          @Override
          public void onSuccess(
              int statusCode,
              cz.msebera.android.httpclient.Header[] headers,
              String responseString) {
            super.onSuccess(statusCode, headers, responseString);
            Log.i(TAG, responseString);
          }

          @Override
          public void onFailure(
              int statusCode,
              cz.msebera.android.httpclient.Header[] headers,
              String responseString,
              Throwable throwable) {
            super.onFailure(statusCode, headers, responseString, throwable);
            Log.v(TAG, responseString, throwable);
          }
        });
  }
Beispiel #20
0
  public void onClickSithLogin(View v) {
    userName = editTextUserName.getText().toString();
    userPassword = editTextPassword.getText().toString();

    requestParams = new RequestParams();
    requestParams.put("userName", userName);
    requestParams.put("password", userPassword);

    client.post(
        SithAPI.AUTHENTICATE_USER,
        requestParams,
        new AsyncHttpResponseHandler() {

          @Override
          public void onStart() {
            super.onStart();
            progress.setTitle("Loggin in");
            progress.setMessage("Please wait....");
            progress.show();
          };

          @Override
          public void onSuccess(String response) {

            try {
              if (Parser.parseResponse(response)) {
                progress.dismiss();
                pref.edit().putString("userID", userName).commit();
                pref.edit().putBoolean("isFB", false).commit();
                sithApplication.setUserID(userName);
                sithApplication.setFB(false);
                Intent intent = new Intent(SithLoginActivity.this, MainActivity.class);
                startActivity(intent);
                SithLoginActivity.this.finish();
              } else {
                UIutil.showAlert(
                    SithLoginActivity.this, "Login Failed", "Invalid usename or password");
              }
            } catch (JSONException e) {
              UIutil.showExceptionAlert(SithLoginActivity.this, e);
            }
          }

          @Override
          public void onFailure(Throwable arg0, String arg1) {
            UIutil.showExceptionAlert(SithLoginActivity.this, new Exception(arg0.toString()));
          }

          @Override
          public void onFinish() {
            progress.dismiss();
            super.onFinish();
          }
        });
  }
  /** 上传图片 */
  private void savePicture(Bitmap bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
    byte[] byte1 = baos.toByteArray();

    AsyncHttpClient client = new AsyncHttpClient();
    RequestParams params = new RequestParams();
    params.put("act", "imageup");
    params.put("soundtrack", new ByteArrayInputStream(byte1), "aa.jpeg"); // aa.jpeg 好像是随意
    client.post(Url.imageup, params, imageup_handler);
  }
 private void read() {
   // TODO Auto-generated method stub
   // 从网络获取数据并且调用Handler来添加到persons里面
   AsyncHttpClient client = new AsyncHttpClient();
   RequestParams params = new RequestParams();
   params.put("act", "list");
   params.put("uid", NApplication.userid);
   params.put("Participate", "0");
   params.put("PageSize", "" + PageSize);
   params.put("PageIndex", "" + PageIndex);
   params.put("IsParticipate", "0");
   Log.e("", Url.Operation + "?" + params);
   client.post(Url.Operation, params, DV_handler);
 }
Beispiel #23
0
  // Method gets called when Broad Case is issued from MainActivity for every 10 seconds
  @Override
  public void onReceive(final Context context, Intent intent) {
    // TODO Auto-generated method stub
    noOfTimes++;
    Toast.makeText(context, "BC Service Running for " + noOfTimes + " times", Toast.LENGTH_SHORT)
        .show();
    AsyncHttpClient client = new AsyncHttpClient();
    RequestParams params = new RequestParams();
    // Checks if new records are inserted in Remote MySQL DB to proceed with Sync operation
    client.post(
        "http://scottbm.5gbfree.com/webservice/mysqlsqlitesync/getdbrowcount.php",
        params,
        new AsyncHttpResponseHandler() {
          @Override
          public void onSuccess(String response) {
            System.out.println(response);
            try {
              // Create JSON object out of the response sent by getdbrowcount.php
              JSONObject obj = new JSONObject(response);
              System.out.println(obj.get("count"));
              // If the count value is not zero, call MyService to display notification
              if (obj.getInt("count") != 0) {
                final Intent intnt = new Intent(context, MyService.class);
                // Set unsynced count in intent data
                intnt.putExtra("intntdata", "Unsynced Rows Count " + obj.getInt("count"));
                // Call MyService
                context.startService(intnt);
              } else {
                Toast.makeText(context, "Sync not needed", Toast.LENGTH_SHORT).show();
              }
            } catch (JSONException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }

          @Override
          public void onFailure(int statusCode, Throwable error, String content) {
            // TODO Auto-generated method stub
            if (statusCode == 404) {
              Toast.makeText(context, "404", Toast.LENGTH_SHORT).show();
            } else if (statusCode == 500) {
              Toast.makeText(context, "500", Toast.LENGTH_SHORT).show();
            } else {
              Toast.makeText(context, "Error occured!", Toast.LENGTH_SHORT).show();
            }
          }
        });
  }
Beispiel #24
0
  /**
   * 返回String数据
   *
   * @param listener
   */
  public void doPostForStringResult(final OnHttpResultListener listener) {
    client.post(
        url,
        params,
        new AsyncHttpResponseHandler() {
          @Override
          public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
            String result = getResultFromHttp(responseBody);
            listener.onHttpResult(result);
          }

          @Override
          public void onFailure(
              int statusCode, Header[] headers, byte[] responseBody, Throwable error) {}
        });
  }
  public void clickSetParams(View v) {

    RequestParams params = new RequestParams();

    params.put("Password", "Dmdhsmdx4");
    params.put("Character2", editText3.getText().toString().trim());
    params.put("Character0", editText1.getText().toString().trim());
    params.put("Character1", editText2.getText().toString().trim());

    System.out.println(params.toString());

    httpClient.post(
        METRO_STEP1,
        params,
        new AsyncHttpResponseHandler() {
          @Override
          public void onSuccess(String response) {

            System.out.println("metrobank2 response " + response);
            // myProgressDialog.dismiss();

            String[] temp;

            /* delimiter */
            String delimiter = "\"";
            /*
             * given string will be split by the argument delimiter
             * provided.
             */
            temp = response.split(delimiter);
            /* print substrings */
            for (int i = 0; i < temp.length; i++) System.out.println(temp[i]);

            firstparameter = temp[1];
            secondparameter = temp[3];

            System.out.println(firstparameter);
            System.out.println(secondparameter);

            clickGetAcc();
          }

          public void onFailure(Throwable error, String content) {
            System.out.println("metrobank2 e1r11ror  " + content);
          }
        });
  }
Beispiel #26
0
 // Method to Sync MySQL to SQLite DB
 public void syncSQLiteMySQLDB1() {
   // Create AsycHttpClient object
   AsyncHttpClient client = new AsyncHttpClient();
   // Http Request Params Object
   RequestParams params = new RequestParams();
   // Show ProgressBar
   prgDialog.show();
   // Make Http call to getusers.php
   client.post(
       "http://scottbm.5gbfree.com/webservice/mysqlsqlitesync/getusers.php",
       params,
       new AsyncHttpResponseHandler() {
         @Override
         public void onSuccess(String response) {
           // Hide ProgressBar
           prgDialog.hide();
           // Update SQLite DB with response sent by getusers.php
           updateSQLite(response);
         }
         // When error occured
         @Override
         public void onFailure(int statusCode, Throwable error, String content) {
           // TODO Auto-generated method stub
           // Hide ProgressBar
           prgDialog.hide();
           if (statusCode == 404) {
             Toast.makeText(
                     getApplicationContext(), "Requested resource not found", Toast.LENGTH_LONG)
                 .show();
           } else if (statusCode == 500) {
             Toast.makeText(
                     getApplicationContext(),
                     "Something went wrong at server end",
                     Toast.LENGTH_LONG)
                 .show();
           } else {
             Toast.makeText(
                     getApplicationContext(),
                     "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet]",
                     Toast.LENGTH_LONG)
                 .show();
           }
         }
       });
 }
 private void makeHTTPCall() {
   pDialog.setMessage("invoking php");
   AsyncHttpClient client = new AsyncHttpClient();
   client.post(
       "http://192.168.2.5:9000/imgupload/upload_image.php",
       params,
       new AsyncHttpResponseHandler() {
         // When the response returned by REST has Http
         // response code '200'
         @Override
         public void onSuccess(String response) {
           pDialog.hide();
           Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show();
         }
         // When the response returned by REST has Http
         // response code other than '200' such as '404',
         // '500' or '403' etc
         @Override
         public void onFailure(int statusCode, Throwable error, String content) {
           pDialog.hide();
           if (statusCode == 404) {
             Toast.makeText(
                     getApplicationContext(), "Requested response not found", Toast.LENGTH_SHORT)
                 .show();
           } else if (statusCode == 500) {
             Toast.makeText(
                     getApplicationContext(),
                     "Something went wrong at server end",
                     Toast.LENGTH_SHORT)
                 .show();
           } else {
             Toast.makeText(
                     getApplicationContext(),
                     "Error occurred \n Most common Error: \n"
                         + "1. Device not connected to Internet\n"
                         + "2. Web App is not deployed in App server\n"
                         + "3. App server is not running\n "
                         + "HTTP Status code :"
                         + statusCode,
                     Toast.LENGTH_SHORT)
                 .show();
           }
         }
       });
 }
  /** 采用AsyncHttpClient的Post方式进行实现 */
  public void loginByAsyncHttpClientPost() {
    String url = "http://api.breadtrip.com/accounts/login/"; // 定义请求的地址
    // 创建请求参数的封装的对象
    RequestParams params = new RequestParams();
    params.put("username", "Sunsg"); // 设置请求的参数名和参数值
    params.put("password", "123456"); // 设置请求的参数名和参数
    client.setUserAgent(
        "BreadTrip/android/4.2.0/zh (android OS4.4.2) htc_m8tl Map/AutoNavi/v1.4.2 (HTC M8t,htc)");
    PersistentCookieStore myCookieStore = new PersistentCookieStore(this);
    client.setCookieStore(myCookieStore);
    // 添加自己的cookiers
    BasicClientCookie newCookie = new BasicClientCookie("domain", ".breadtrip.com"); // name = value
    //        newCookie.setVersion(1);
    //        newCookie.setDomain(".breadtrip.com");
    //        newCookie.setPath("/");
    myCookieStore.addCookie(newCookie);
    // 执行post方法
    client.post(
        url,
        params,
        new AsyncHttpResponseHandler() {
          //
          /** 成功处理的方法 statusCode:响应的状态码; headers:相应的头信息 比如 响应的时间,响应的服务器 ; responseBody:响应内容的字节 */
          @Override
          public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
            if (statusCode == 200) {
              for (int i = 0; i < headers.length; i++) {
                Logger.e("test", " header " + i + " = " + headers[i]);
              }

              Logger.e("test", "responsebody = " + new String(responseBody));
              syncCookies();
            }
          }
          /** 失败处理的方法 error:响应失败的错误信息封装到这个异常对象中 */
          @Override
          public void onFailure(
              int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
            error.printStackTrace(); // 把错误信息打印出轨迹来
            Logger.e("test", "error = " + error.toString());
          }
        });
  }
Beispiel #29
0
  /**
   * Function to realize a HTTP Post call
   *
   * @param url
   * @param RequestParams
   */
  protected void httpPost(String url, RequestParams params) {
    params.put("uiid", uiid);
    debug("URL: " + url + ".");
    client.post(
        getBaseContext(),
        getString(R.string.api) + url,
        params,
        new AsyncHttpResponseHandler() {
          @Override
          public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
            debug("Failure POST.");
          }

          @Override
          public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
            debug("Success POST.");
          }
        });
  }
  /** 获取订单号 */
  private void getOrderNum() {
    String url = Url.AddRecharge_URL;
    AsyncHttpClient client = new AsyncHttpClient();
    RequestParams params = new RequestParams();
    params.put("rechargeaccount", cz_money);
    params.put("userid", PreferenceUtils.getUserId());
    params.put("bankname", bankname);

    client.post(
        url,
        params,
        new AsyncHttpResponseHandler() {
          @Override
          public void onSuccess(int i, Header[] headers, byte[] bytes) {
            Log.d("getOrderNum ---->", new String(bytes));

            try {
              AddRechargeBean addRechargeBean =
                  new GsonBuilder().create().fromJson(new String(bytes), AddRechargeBean.class);
              AddRechargeItemBean addRechargeItemBean = addRechargeBean.getRecharge();
              billno = addRechargeItemBean.getBillno();
              TXWLProgressDialog.Dismiss();

              if (getIntent().getBooleanExtra("isDetele", false)) {
                TXWLProgressDialog.createDialog(AddBankCardActivity.this);
                TXWLProgressDialog.setMessage("只能绑定一张银行卡,解绑中");
                new UnBindBeiFu().execute();
              }

            } catch (Exception e) {
              TXWLApplication.getInstance().showErrorConnected(e);
              TXWLProgressDialog.Dismiss();
            }
          }

          @Override
          public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
            TXWLProgressDialog.Dismiss();
            TXWLApplication.getInstance().showTextToast("网络错误, 获取订单号失败,请重新选择银行");
          }
        });
    //
  }