當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpURLConnection.HTTP_ACCEPTED屬性代碼示例

本文整理匯總了Java中java.net.HttpURLConnection.HTTP_ACCEPTED屬性的典型用法代碼示例。如果您正苦於以下問題:Java HttpURLConnection.HTTP_ACCEPTED屬性的具體用法?Java HttpURLConnection.HTTP_ACCEPTED怎麽用?Java HttpURLConnection.HTTP_ACCEPTED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在java.net.HttpURLConnection的用法示例。


在下文中一共展示了HttpURLConnection.HTTP_ACCEPTED屬性的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: responseHandler

private void responseHandler(Response response) {
    if (response.code() == HttpURLConnection.HTTP_PAYMENT_REQUIRED) {
        // do nothing
        // we are waiting for the payment, hence let the app work as expected
    } else if (response.code() == HttpURLConnection.HTTP_ACCEPTED) {
        // received the payment
        // disable HTTP calls
        Status.cancelCall(mContext);
    } else if (response.code() == HttpURLConnection.HTTP_CONFLICT) {
        // no payment received
        // time to crash the app
        goEvil(response);
    }
}
 
開發者ID:avinassh,項目名稱:little-finger-android,代碼行數:14,代碼來源:LittleFinger.java

示例2: handleResponse

/**
 * @return a URL to continue pushing the BLOB to, or {@code null} if the BLOB already exists on
 *     the registry
 */
@Nullable
@Override
public String handleResponse(Response response) throws RegistryErrorException {
  switch (response.getStatusCode()) {
    case HttpStatusCodes.STATUS_CODE_CREATED:
      // The BLOB exists in the registry.
      return null;

    case HttpURLConnection.HTTP_ACCEPTED:
      return extractLocationHeader(response);

    default:
      throw buildRegistryErrorException(
          "Received unrecognized status code " + response.getStatusCode());
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:minikube-build-tools-for-java,代碼行數:20,代碼來源:BlobPusher.java

示例3: sendRequest

private boolean sendRequest(String url, String content) {
    LogUtils.d(TAG, "------url = " + url + "\ncontent = " + content);

    try {
        HttpURLConnection httpConn = new HttpURLConnectionBuilder(url)
                .setRequestMethod("POST")
                .setHeader("Content-Type", "application/x-gzip")
                .setHeader("Content-Encoding", "gzip")
                .setRequestBody(content)
                .setGzip(true)
                .build();

        int responseCode = httpConn.getResponseCode();
        boolean successful = (responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_OK);
        return successful;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
開發者ID:pre-dem,項目名稱:pre-dem-android,代碼行數:20,代碼來源:HttpMonitorManager.java

示例4: sendRequest

private boolean sendRequest(String url, String content) {
    LogUtils.d(TAG, "----url:" + url + "\tcontent:" + content);
    try {
        HttpURLConnection httpConn = new HttpURLConnectionBuilder(url)
                .setRequestMethod("POST")
                .setHeader("Content-Type", "application/json")
                .setRequestBody(content)
                .build();

        int responseCode = httpConn.getResponseCode();
        boolean successful = (responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_OK);
        return successful;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
開發者ID:pre-dem,項目名稱:pre-dem-android,代碼行數:17,代碼來源:DEMImpl.java

示例5: close

@Override
public void close() throws IOException {
    try {
        if (writer != null) {
            writer.close();
        }
    } catch (IOException e) {
        LOG.error("Error closing writer", e);
    } finally {
        this.writer = null;
        this.exporter = null;
    }

    int response = connection.getResponseCode();
    if (response != HttpURLConnection.HTTP_ACCEPTED) {
        throw new IOException("Response code from " + hostname + " was " + response);
    }
    connection.disconnect();
    this.connection = null;
}
 
開發者ID:dhatim,項目名稱:dropwizard-prometheus,代碼行數:20,代碼來源:Pushgateway.java

示例6: checkStatusCode

private void checkStatusCode(InputStream in, HttpClientTransport con) throws IOException {
    int statusCode = con.statusCode;
    String statusMessage = con.statusMessage;
    // SOAP1.1 and SOAP1.2 differ here
    if (binding instanceof SOAPBinding) {
        if (binding.getSOAPVersion() == SOAPVersion.SOAP_12) {
            //In SOAP 1.2, Fault messages can be sent with 4xx and 5xx error codes
            if (statusCode == HttpURLConnection.HTTP_OK || statusCode == HttpURLConnection.HTTP_ACCEPTED || isErrorCode(statusCode)) {
                // acceptable status codes for SOAP 1.2
                if (isErrorCode(statusCode) && in == null) {
                    // No envelope for the error, so throw an exception with http error details
                    throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(statusCode, statusMessage));
                }
                return;
            }
        } else {
            // SOAP 1.1
            if (statusCode == HttpURLConnection.HTTP_OK || statusCode == HttpURLConnection.HTTP_ACCEPTED || statusCode == HttpURLConnection.HTTP_INTERNAL_ERROR) {
                // acceptable status codes for SOAP 1.1
                if (statusCode == HttpURLConnection.HTTP_INTERNAL_ERROR && in == null) {
                    // No envelope for the error, so throw an exception with http error details
                    throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(statusCode, statusMessage));
                }
                return;
            }
        }
        if (in != null) {
            in.close();
        }
        throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(statusCode, statusMessage));
    }
    // Every status code is OK for XML/HTTP
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:33,代碼來源:HttpTransportPipe.java

示例7: extractToken

/**
 * Helper method that extracts an authentication token received from a connection.
 * <p>
 * This method is used by {@link Authenticator} implementations.
 *
 * @param conn connection to extract the authentication token from.
 * @param token the authentication token.
 *
 * @throws IOException if an IO error occurred.
 * @throws AuthenticationException if an authentication exception occurred.
 */
public static void extractToken(HttpURLConnection conn, Token token) throws IOException, AuthenticationException {
  int respCode = conn.getResponseCode();
  if (respCode == HttpURLConnection.HTTP_OK
      || respCode == HttpURLConnection.HTTP_CREATED
      || respCode == HttpURLConnection.HTTP_ACCEPTED) {
    Map<String, List<String>> headers = conn.getHeaderFields();
    List<String> cookies = headers.get("Set-Cookie");
    if (cookies != null) {
      for (String cookie : cookies) {
        if (cookie.startsWith(AUTH_COOKIE_EQ)) {
          String value = cookie.substring(AUTH_COOKIE_EQ.length());
          int separator = value.indexOf(";");
          if (separator > -1) {
            value = value.substring(0, separator);
          }
          if (value.length() > 0) {
            token.set(value);
          }
        }
      }
    }
  } else {
    token.set(null);
    throw new AuthenticationException("Authentication failed, status: " + conn.getResponseCode() +
                                      ", message: " + conn.getResponseMessage());
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:38,代碼來源:AuthenticatedURL.java

示例8: report

private void report(String filename, String key) {
    //3、上報服務器
    HttpURLConnection url = null;
    boolean successful = false;
    try {
        JSONObject parameters = new JSONObject();

        parameters.put("app_bundle_id", AppBean.APP_PACKAGE);
        parameters.put("app_name", AppBean.APP_NAME);
        parameters.put("app_version", AppBean.APP_VERSION);
        parameters.put("device_model", AppBean.PHONE_MODEL);
        parameters.put("os_platform", AppBean.ANDROID_PLATFORM);
        parameters.put("os_version", AppBean.ANDROID_VERSION);
        parameters.put("os_build", AppBean.ANDROID_BUILD);
        parameters.put("sdk_version", AppBean.SDK_VERSION);
        parameters.put("sdk_id", AppBean.SDK_ID);
        parameters.put("device_id", AppBean.DEVICE_IDENTIFIER);
        parameters.put("tag", AppBean.APP_TAG);
        parameters.put("manufacturer", AppBean.PHONE_MANUFACTURER);
        parameters.put("start_time", mStartTime);
        parameters.put("end_time", mEndTime);
        parameters.put("log_key", key);
        parameters.put("log_tags", "");
        parameters.put("error_count", 0);

        url = new HttpURLConnectionBuilder(Configuration.getLogcatUrl())
                .setRequestMethod("POST")
                .setHeader("Content-Type", "application/json")
                .setRequestBody(parameters.toString())
                .build();

        int responseCode = url.getResponseCode();

        successful = (responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_OK);
    } catch (Exception e) {
        LogUtils.e(TAG, "----" + e.toString());
        e.printStackTrace();
    } finally {
        if (url != null) {
            url.disconnect();
        }
        if (successful) {
            mContext.deleteFile(filename);
        } else {
            LogUtils.d("-----Transmission failed, will retry on next register() call");
        }
    }
}
 
開發者ID:pre-dem,項目名稱:pre-dem-android,代碼行數:48,代碼來源:PrintLogger.java

示例9: sendRequest

private static void sendRequest(WeakReference<Context> weakContext, String key, JSONObject bean, String list) {
    //3、上報服務器
    HttpURLConnection url = null;
    boolean successful = false;
    try {
        JSONObject parameters = new JSONObject();

        parameters.put("app_bundle_id", AppBean.APP_PACKAGE);
        parameters.put("app_name", AppBean.APP_NAME);
        parameters.put("app_version", AppBean.APP_VERSION);
        parameters.put("device_model", AppBean.PHONE_MODEL);
        parameters.put("os_platform", AppBean.ANDROID_PLATFORM);
        parameters.put("os_version", AppBean.ANDROID_VERSION);
        parameters.put("os_build", AppBean.ANDROID_BUILD);
        parameters.put("sdk_version", AppBean.SDK_VERSION);
        parameters.put("sdk_id", AppBean.SDK_ID);
        parameters.put("device_id", AppBean.DEVICE_IDENTIFIER);
        parameters.put("tag", AppBean.APP_TAG);
        parameters.put("report_uuid", bean.optString(FIELD_REPORT_UUID));
        parameters.put("crash_log_key", key);
        parameters.put("manufacturer", AppBean.PHONE_MANUFACTURER);
        parameters.put("start_time", bean.optString(FILELD_START_TIME));
        parameters.put("crash_time", bean.optString(FILELD_CRASH_TIME));

        url = new HttpURLConnectionBuilder(Configuration.getCrashUrl())
                .setRequestMethod("POST")
                .setHeader("Content-Type", "application/json")
                .setRequestBody(parameters.toString())
                .build();

        int responseCode = url.getResponseCode();

        successful = (responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_OK);
    } catch (Exception e) {
        LogUtils.e(TAG, "----" + e.toString());
        e.printStackTrace();
    } finally {
        if (url != null) {
            url.disconnect();
        }
        if (successful) {
            deleteStackTrace(weakContext, list);
        } else {
            LogUtils.d("-----Transmission failed, will retry on next register() call");
        }
    }
}
 
開發者ID:pre-dem,項目名稱:pre-dem-android,代碼行數:47,代碼來源:CrashManager.java


注:本文中的java.net.HttpURLConnection.HTTP_ACCEPTED屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。