public class HttpUtils { private static final String BASE_URL = "http://api.twitter.com/1/"; private static AsyncHttpClient client = new AsyncHttpClient(); public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.get(getAbsoluteUrl(url), params, responseHandler); } public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.post(getAbsoluteUrl(url), params, responseHandler); } public static void getByUrl(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.get(url, params, responseHandler); } public static void postByUrl(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.post(url, params, responseHandler); } private static String getAbsoluteUrl(String relativeUrl) { return BASE_URL + relativeUrl; } }
final class WebRequest { private AsyncHttpClient mClient = new AsyncHttpClient(); public static void callService(AsyncHttpResponseHandler handler) { mClient.post("http://domain.com/dp/index.php", handler); } }
AsyncHttpClient client = new AsyncHttpClient(); client.post("URL", params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { } });
AsyncHttpClient client = new AsyncHttpClient(); client.post("https://url.com/getdata?username=abcd123&password=123456", new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { // success } @Override public void onFailure(Throwable error, String content) { // something went wrong } });
String file = getImagePath().toString();//get path of file you want to upload File myfile_one=new File(file); try { params.put("image1", myfile_one);//image 1 is the key(it uses key-value pair) } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } AsyncHttpClient client=new AsyncHttpClient(); client.post(Constant.url_two, params,new AsyncHttpResponseHandler(){ //here implement the methods of library and write rest of your code }
Map<String, String> aMap = new HashMap<String, String>(); aMap.put("f_name" ,""); aMap.put("l_name" ,""); aMap.put("email" ,edtEmail.getText().toString()); RequestParams params = new RequestParams(); params.put("user",aMap); AsyncHttpClient client = new AsyncHttpClient(); client.post(url, params, n.....
RequestParam params = new RequestParams(); params.put("key1", "value1"); params.put("key2", "value2"); File imgFile = new File(filePath); try { params.put("file",imgFile); } catch(FileNotFoundException e) {} AsyncHttpClient image = new AsyncHttpClient(); image.post(uploadURL, params, new AsyncHttpResponseHandler(){});
// Create AsycHttpClient object AsyncHttpClient client = new AsyncHttpClient(); // Http Request Params Object RequestParams params = new RequestParams(); params.put("app_pkg", getPackageName().toString()); client.post("www.myapiKeysHolder.com", params, new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { String api=response; //Api give your Api Key updateSQLite("api_key",api); } });
public class MyCLient{ private static AsyncHttpClient client = new AsyncHttpClient(); public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.get(url, params, responseHandler); } public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) { client.post(url, params, responseHandler); }
RequestParams params=new RequestParams(); String file = getImagePath().toString();//get path of file you want to upload File myfile_one=new File(file); try { params.put("image1", myfile_one);//image 1 is the key(it uses key-value pair) } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } AsyncHttpClient client=new AsyncHttpClient(); client.post(Constant.url_two, params,new AsyncHttpResponseHandler(){ //here implement the methods of library and write rest of your code }
AsyncHttpClient client = new AsyncHttpClient(); File myFile = new File("/path/to/file.png"); RequestParams params = new RequestParams(); try { params.put("profile_picture", myFile); client.post("http://www.yourserver.com/upload.php", params, responseHandler); } catch(FileNotFoundException e) { // handle }
if (resultCode == Activity.RESULT_OK) { //blah blah blah all the code that decodes and adds it to the listview AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); params.put("qrcode", "XXXXXXXXXXXXX"); client.post("myserver.com/API/addqr", params, new JsonHttpResponseHandler() { public void onSuccess(int statusCode, Header[] headers, JSONObject response) { //do something with the response, if there is one. } }); }
AsyncHttpClient asynClient = new AsyncHttpClient(); void post(Context context,String url, StringEntity entity,String string, AsyncHttpResponseHandler asyncHttpResponseHandler) { asynClient.addHeader("Accept", "application/json"); asynClient.addHeader("Content-type", "application/json"); asynClient.post(context, url, entity, "application/json", asyncHttpResponseHandler ); }
AsyncHttpClient client = new AsyncHttpClient(); String filename = "file.png"; File myFile = new File("/path/to/" + filename); RequestParams params = new RequestParams(); try { params.put("file", myFile); params.put("filename", filename); client.post("http://192.168.1.105:8080/ATestInternetCameraServlet/CameraServlet", params, responseHandler); } catch(FileNotFoundException e) { // handle }
AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); params.put("notes", "Test api support"); client.post(restApiUrl, params, responseHandler);
AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); params.put("email", "u"); params.put("password", "pass"); client.post("http://host?method=signIn", params, new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { // handle response here } });
AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); params.put("username",username); params.put("password",pass); client.post("http://www.example.com/", params, new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { //parse data with Jsoup } });
RequestParams params = new RequestParams(); params.put("username", "abcd123"); params.put("password", "123456"); AsyncHttpClient client = new AsyncHttpClient(); client.post("https://url.com/getdata", params, new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { // success } @Override public void onFailure(Throwable error, String content) { // something went wrong } });
AsyncHttpClient client = new AsyncHttpClient(); RequestParams rp = new RequestParams(); rp.put("email", un.getText().toString()); rp.put("password", pw.getText().toString()); client.post("http://www.mywebsite.com/thatoneloginscript.php", rp, new AsyncHttpResponseHandler() { @Override public final void onSuccess(String response) { // handle your response here } @Override public void onFailure(Throwable e, String response) { // something went wrong } });
AsyncHttpClient client = new AsyncHttpClient(); RequestParams rp = new RequestParams(); rp.put("pLat", "some value"); rp.put("pLong", "some other value"); client.post("http://10.0.2.2/welcome.php", rp, new AsyncHttpResponseHandler() { @Override public final void onSuccess(String response) { // handle your response here } @Override public void onFailure(Throwable e, String response) { // something went wrong } });