本文整理汇总了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);
}
}
示例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());
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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
}
示例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());
}
}
示例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");
}
}
}
示例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");
}
}
}