com.androidnetworking.AndroidNetworking.get()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(12.7k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中com.androidnetworking.AndroidNetworking.get()方法的一些代码示例,展示了AndroidNetworking.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AndroidNetworking.get()方法的具体详情如下:
包路径:com.androidnetworking.AndroidNetworking
类名称:AndroidNetworking
方法名:get

AndroidNetworking.get介绍

[英]Method to make GET request
[中]方法发出GET请求

代码示例

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

public void testObjectGetRequest() throws InterruptedException {
  server.enqueue(new MockResponse().setBody("{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}"));
  final AtomicReference<String> firstNameRef = new AtomicReference<>();
  final AtomicReference<String> lastNameRef = new AtomicReference<>();
  final CountDownLatch latch = new CountDownLatch(1);
  AndroidNetworking.get(server.url("/").toString())
      .build()
      .getAsObject(User.class, new ParsedRequestListener<User>() {
        @Override
        public void onResponse(User user) {
          firstNameRef.set(user.firstName);
          lastNameRef.set(user.lastName);
          latch.countDown();
        }
        @Override
        public void onError(ANError anError) {
          assertTrue(false);
        }
      });
  assertTrue(latch.await(2, SECONDS));
  assertEquals("Amit", firstNameRef.get());
  assertEquals("Shekhar", lastNameRef.get());
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

public void prefetch(View view) {
  AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY)
      .addPathParameter("pageNumber", "0")
      .addQueryParameter("limit", "3")
      .setTag(this)
      .setPriority(Priority.LOW)
      .build()
      .setAnalyticsListener(new AnalyticsListener() {
        @Override
        public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
          Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
          Log.d(TAG, " bytesSent : " + bytesSent);
          Log.d(TAG, " bytesReceived : " + bytesReceived);
          Log.d(TAG, " isFromCache : " + isFromCache);
        }
      })
      .prefetch();
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

public void prefetch(View view) {
  AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY)
      .addPathParameter("pageNumber", "0")
      .addQueryParameter("limit", "3")
      .setTag(this)
      .setPriority(Priority.LOW)
      .build()
      .setAnalyticsListener(new AnalyticsListener() {
        @Override
        public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
          Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
          Log.d(TAG, " bytesSent : " + bytesSent);
          Log.d(TAG, " bytesReceived : " + bytesReceived);
          Log.d(TAG, " isFromCache : " + isFromCache);
        }
      })
      .prefetch();
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSynchronousJSONArrayGetRequest() throws InterruptedException, JSONException {
  server.enqueue(new MockResponse().setBody("[{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}]"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<JSONArray> response = request.executeForJSONArray();
  JSONObject jsonObject = response.getResult().getJSONObject(0);
  assertEquals("Amit", jsonObject.getString("firstName"));
  assertEquals("Shekhar", jsonObject.getString("lastName"));
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSyncResponseBodyGet() throws InterruptedException, IOException {
  server.enqueue(new MockResponse().setBody("data"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<Response> response = request.executeForOkHttpResponse();
  assertEquals("data", response.getResult().body().string());
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

public void testStringGetRequest() throws InterruptedException {
  server.enqueue(new MockResponse().setBody("data"));
  final AtomicReference<String> responseRef = new AtomicReference<>();
  final CountDownLatch latch = new CountDownLatch(1);
  AndroidNetworking.get(server.url("/").toString())
      .build()
      .getAsString(new StringRequestListener() {
        @Override
        public void onResponse(String response) {
          responseRef.set(response);
          latch.countDown();
        }
        @Override
        public void onError(ANError anError) {
          assertTrue(false);
        }
      });
  assertTrue(latch.await(2, SECONDS));
  assertEquals("data", responseRef.get());
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSyncResponseBodyGet404() throws InterruptedException, IOException {
  server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<Response> response = request.executeForOkHttpResponse();
  assertEquals("data", response.getResult().body().string());
  assertEquals(404, response.getResult().code());
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSynchronousJSONObjectGetRequest() throws InterruptedException, JSONException {
  server.enqueue(new MockResponse().setBody("{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<JSONObject> response = request.executeForJSONObject();
  assertEquals("Amit", response.getResult().getString("firstName"));
  assertEquals("Shekhar", response.getResult().getString("lastName"));
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSynchronousObjectListGetRequest() throws InterruptedException, JSONException {
  server.enqueue(new MockResponse().setBody("[{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}]"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<List<User>> response = request.executeForObjectList(User.class);
  User user = response.getResult().get(0);
  assertEquals("Amit", user.firstName);
  assertEquals("Shekhar", user.lastName);
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSynchronousObjectListGetRequest() throws InterruptedException, JSONException {
  server.enqueue(new MockResponse().setBody("[{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}]"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<List<User>> response = request.executeForObjectList(User.class);
  User user = response.getResult().get(0);
  assertEquals("Amit", user.firstName);
  assertEquals("Shekhar", user.lastName);
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSynchronousStringGetRequest() throws InterruptedException {
  server.enqueue(new MockResponse().setBody("data"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<String> response = request.executeForString();
  assertEquals("data", response.getResult());
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSynchronousObjectGetRequest() throws InterruptedException, JSONException {
  server.enqueue(new MockResponse().setBody("{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<User> response = request.executeForObject(User.class);
  assertEquals("Amit", response.getResult().firstName);
  assertEquals("Shekhar", response.getResult().lastName);
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSynchronousObjectGetRequest() throws InterruptedException, JSONException {
  server.enqueue(new MockResponse().setBody("{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<User> response = request.executeForObject(User.class);
  assertEquals("Amit", response.getResult().firstName);
  assertEquals("Shekhar", response.getResult().lastName);
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSynchronousJSONObjectGetRequest404() throws InterruptedException {
  server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<JSONObject> response = request.executeForJSONObject();
  ANError error = response.getError();
  assertEquals("data", error.getErrorBody());
  assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, error.getErrorDetail());
  assertEquals(404, error.getErrorCode());
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSynchronousStringGetRequest404() throws InterruptedException {
  server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<String> response = request.executeForString();
  ANError error = response.getError();
  assertEquals("data", error.getErrorBody());
  assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, error.getErrorDetail());
  assertEquals(404, error.getErrorCode());
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSynchronousJSONArrayGetRequest404() throws InterruptedException {
  server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<JSONObject> response = request.executeForJSONArray();
  ANError error = response.getError();
  assertEquals("data", error.getErrorBody());
  assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, error.getErrorDetail());
  assertEquals(404, error.getErrorCode());
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSynchronousObjectGetRequest404() throws InterruptedException {
  server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<User> response = request.executeForObject(User.class);
  ANError error = response.getError();
  assertEquals("data", error.getErrorBody());
  assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, error.getErrorDetail());
  assertEquals(404, error.getErrorCode());
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSynchronousObjectListGetRequest404() throws InterruptedException {
  server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<List<User>> response = request.executeForObjectList(User.class);
  ANError error = response.getError();
  assertEquals("data", error.getErrorBody());
  assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, error.getErrorDetail());
  assertEquals(404, error.getErrorCode());
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSynchronousObjectGetRequest404() throws InterruptedException {
  server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<User> response = request.executeForObject(User.class);
  ANError error = response.getError();
  assertEquals("data", error.getErrorBody());
  assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, error.getErrorDetail());
  assertEquals(404, error.getErrorCode());
}

代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking

@SuppressWarnings("unchecked")
public void testSynchronousObjectListGetRequest404() throws InterruptedException {
  server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
  ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
  ANResponse<List<User>> response = request.executeForObjectList(User.class);
  ANError error = response.getError();
  assertEquals("data", error.getErrorBody());
  assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, error.getErrorDetail());
  assertEquals(404, error.getErrorCode());
}

相关文章