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

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

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

AndroidNetworking.post介绍

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

代码示例

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

@SuppressWarnings("unchecked")
public void testSynchronousJSONArrayPostRequest() throws InterruptedException, JSONException {
  server.enqueue(new MockResponse().setBody("[{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}]"));
  ANRequest request = AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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 testSyncResponseBodyPost() throws InterruptedException, IOException {
  server.enqueue(new MockResponse().setBody("data"));
  ANRequest request = AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .build();
  ANResponse<Response> response = request.executeForOkHttpResponse();
  assertEquals("data", response.getResult().body().string());
}

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

public void testObjectListPostRequest() 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.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .build()
      .getAsObjectList(User.class, new ParsedRequestListener<List<User>>() {
        @Override
        public void onResponse(List<User> userList) {
          firstNameRef.set(userList.get(0).firstName);
          lastNameRef.set(userList.get(0).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 testObjectPostRequest() 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.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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 testObjectPostRequest() 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.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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

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

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

public void testStringPostRequest() throws InterruptedException {
  server.enqueue(new MockResponse().setBody("data"));
  final AtomicReference<String> responseRef = new AtomicReference<>();
  final CountDownLatch latch = new CountDownLatch(1);
  AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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 testSynchronousJSONObjectPostRequest() throws InterruptedException, JSONException {
  server.enqueue(new MockResponse().setBody("{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}"));
  ANRequest request = AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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 testSynchronousObjectListPostRequest() throws InterruptedException, JSONException {
  server.enqueue(new MockResponse().setBody("[{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}]"));
  ANRequest request = AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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 testSynchronousObjectListPostRequest() throws InterruptedException, JSONException {
  server.enqueue(new MockResponse().setBody("[{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}]"));
  ANRequest request = AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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 testSynchronousStringPostRequest() throws InterruptedException {
  server.enqueue(new MockResponse().setBody("data"));
  ANRequest request = AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .build();
  ANResponse<String> response = request.executeForString();
  assertEquals("data", response.getResult());
}

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

@SuppressWarnings("unchecked")
public void testSynchronousObjectPostRequest() throws InterruptedException, JSONException {
  server.enqueue(new MockResponse().setBody("{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}"));
  ANRequest request = AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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 testSynchronousObjectPostRequest() throws InterruptedException, JSONException {
  server.enqueue(new MockResponse().setBody("{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}"));
  ANRequest request = AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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 testSynchronousObjectListPostRequest404() throws InterruptedException {
  server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
  ANRequest request = AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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 testSynchronousObjectPostRequest404() throws InterruptedException {
  server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
  ANRequest request = AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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 testSynchronousJSONObjectPostRequest404() throws InterruptedException {
  server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
  ANRequest request = AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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 testSynchronousStringPostRequest404() throws InterruptedException {
  server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
  ANRequest request = AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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 testSynchronousObjectPostRequest404() throws InterruptedException {
  server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
  ANRequest request = AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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 testSynchronousJSONArrayPostRequest404() throws InterruptedException {
  server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
  ANRequest request = AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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 testSynchronousObjectListPostRequest404() throws InterruptedException {
  server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
  ANRequest request = AndroidNetworking.post(server.url("/").toString())
      .addBodyParameter("fistName", "Amit")
      .addBodyParameter("lastName", "Shekhar")
      .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());
}

相关文章