use of com.androidnetworking.common.ANResponse in project Fast-Android-Networking by amitshekhariitbhu.
the class InternalRunnable method executeUploadRequest.
private void executeUploadRequest() {
Response okHttpResponse = null;
try {
okHttpResponse = InternalNetworking.performUploadRequest(request);
if (okHttpResponse == null) {
deliverError(request, Utils.getErrorForConnection(new ANError()));
return;
}
if (request.getResponseAs() == ResponseType.OK_HTTP_RESPONSE) {
request.deliverOkHttpResponse(okHttpResponse);
return;
}
if (okHttpResponse.code() >= 400) {
deliverError(request, Utils.getErrorForServerResponse(new ANError(okHttpResponse), request, okHttpResponse.code()));
return;
}
ANResponse response = request.parseResponse(okHttpResponse);
if (!response.isSuccess()) {
deliverError(request, response.getError());
return;
}
response.setOkHttpResponse(okHttpResponse);
request.deliverResponse(response);
} catch (Exception e) {
deliverError(request, Utils.getErrorForConnection(new ANError(e)));
} finally {
SourceCloseUtil.close(okHttpResponse, request);
}
}
use of com.androidnetworking.common.ANResponse in project Fast-Android-Networking by amitshekhariitbhu.
the class MultipartStringApiTest method testSyncResponseBodyMultipart404.
@SuppressWarnings("unchecked")
public void testSyncResponseBodyMultipart404() throws InterruptedException, IOException {
server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
ANRequest request = AndroidNetworking.upload(server.url("/").toString()).addMultipartParameter("key", "value").build();
ANResponse<Response> response = request.executeForOkHttpResponse();
assertEquals("data", response.getResult().body().string());
assertEquals(404, response.getResult().code());
}
use of com.androidnetworking.common.ANResponse in project Fast-Android-Networking by amitshekhariitbhu.
the class PostStringApiTest method testSyncResponseBodyPost.
@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());
}
Aggregations