コード例 #1
0
 @Override
 public void run() {
   try {
     HttpRequest request = HttpRequest.put(this.getUrlString());
     this.setupSecurity(request);
     request.acceptCharset(CHARSET);
     request.headers(this.getHeaders());
     request.form(this.getParams());
     int code = request.code();
     String body = request.body(CHARSET);
     JSONObject response = new JSONObject();
     response.put("status", code);
     if (code >= 200 && code < 300) {
       response.put("data", body);
       this.getCallbackContext().success(response);
     } else {
       response.put("error", body);
       this.getCallbackContext().error(response);
     }
   } catch (JSONException e) {
     this.respondWithError("There was an error generating the response");
   } catch (HttpRequestException e) {
     if (e.getCause() instanceof UnknownHostException) {
       this.respondWithError(0, "The host could not be resolved");
     } else if (e.getCause() instanceof SSLHandshakeException) {
       this.respondWithError("SSL handshake failed");
     } else {
       this.respondWithError("There was an error with the request");
     }
   }
 }
コード例 #2
0
 private HttpRequest signUpRequest(String emailValue, String passValue) {
   return HttpRequest.put(CONTAINER_URL + PATH + "up")
       .contentType("application/json")
       .send(new GsonSerializer().toJson(new Credentials(emailValue, passValue)));
 }