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


Java HttpURLConnection.HTTP_MULT_CHOICE屬性代碼示例

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


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

示例1: isCacheable

/**
 * Returns true if this response can be stored to later serve another
 * request.
 */
public boolean isCacheable(RequestHeaders request) {
  // Always go to network for uncacheable response codes (RFC 2616, 13.4),
  // This implementation doesn't support caching partial content.
  int responseCode = headers.getResponseCode();
  if (responseCode != HttpURLConnection.HTTP_OK
      && responseCode != HttpURLConnection.HTTP_NOT_AUTHORITATIVE
      && responseCode != HttpURLConnection.HTTP_MULT_CHOICE
      && responseCode != HttpURLConnection.HTTP_MOVED_PERM
      && responseCode != HttpURLConnection.HTTP_GONE) {
    return false;
  }

  // Responses to authorized requests aren't cacheable unless they include
  // a 'public', 'must-revalidate' or 's-maxage' directive.
  if (request.hasAuthorization() && !isPublic && !mustRevalidate && sMaxAgeSeconds == -1) {
    return false;
  }

  if (noStore) {
    return false;
  }

  return true;
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:28,代碼來源:ResponseHeaders.java

示例2: isRedirect

private static boolean isRedirect(int code) {
    return code == HttpURLConnection.HTTP_MOVED_PERM
            || code == HttpURLConnection.HTTP_MOVED_TEMP
            || code == HttpURLConnection.HTTP_SEE_OTHER
            || code == HttpURLConnection.HTTP_MULT_CHOICE
            || code == HTTP_TEMPORARY_REDIRECT
            || code == HTTP_PERMANENT_REDIRECT;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:RedirectHandler.java

示例3: isHttpRedirect

private static boolean isHttpRedirect(int responseCode) {
  switch (responseCode) {
    case HttpURLConnection.HTTP_MULT_CHOICE:
    case HttpURLConnection.HTTP_MOVED_PERM:
    case HttpURLConnection.HTTP_MOVED_TEMP:
    case HttpURLConnection.HTTP_SEE_OTHER:
    case HTTP_TEMPORARY_REDIRECT:
    case HTTP_PERMANENT_REDIRECT:
      return true;
    default:
      return false;
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:HttpUrlConnectionNetworkFetcher.java

示例4: unredirect

public static URI unredirect(URI uri) throws IOException {
  if (!REDIRECTOR_DOMAINS.contains(uri.getHost())) {
    return uri;
  }
  URL url = uri.toURL();
  HttpURLConnection connection = safelyOpenConnection(url);
  connection.setInstanceFollowRedirects(false);
  connection.setDoInput(false);
  connection.setRequestMethod("HEAD");
  connection.setRequestProperty("User-Agent", "ZXing (Android)");
  try {
    int responseCode = safelyConnect(uri.toString(), connection);
    switch (responseCode) {
      case HttpURLConnection.HTTP_MULT_CHOICE:
      case HttpURLConnection.HTTP_MOVED_PERM:
      case HttpURLConnection.HTTP_MOVED_TEMP:
      case HttpURLConnection.HTTP_SEE_OTHER:
      case 307: // No constant for 307 Temporary Redirect ?
        String location = connection.getHeaderField("Location");
        if (location != null) {
          try {
            return new URI(location);
          } catch (URISyntaxException e) {
            // nevermind
          }
        }
    }
    return uri;
  } finally {
    connection.disconnect();
  }
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:32,代碼來源:HttpHelper.java

示例5: unredirect

public static URI unredirect(URI uri) throws IOException {
  if (!REDIRECTOR_DOMAINS.contains(uri.getHost())) {
    return uri;
  }
  URL url = uri.toURL();
  HttpURLConnection connection = safelyOpenConnection(url);
  connection.setInstanceFollowRedirects(false);
  connection.setDoInput(false);
  connection.setRequestMethod("HEAD");
  connection.setRequestProperty("User-Agent", "ZXing (Android)");
  try {
    int responseCode = safelyConnect(connection);
    switch (responseCode) {
      case HttpURLConnection.HTTP_MULT_CHOICE:
      case HttpURLConnection.HTTP_MOVED_PERM:
      case HttpURLConnection.HTTP_MOVED_TEMP:
      case HttpURLConnection.HTTP_SEE_OTHER:
      case 307: // No constant for 307 Temporary Redirect ?
        String location = connection.getHeaderField("Location");
        if (location != null) {
          try {
            return new URI(location);
          } catch (URISyntaxException e) {
            // nevermind
          }
        }
    }
    return uri;
  } finally {
    connection.disconnect();
  }
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:32,代碼來源:HttpHelper.java

示例6: isRedirection

private static boolean isRedirection(int code) {
    return code == HttpURLConnection.HTTP_MOVED_PERM
            || code == HttpURLConnection.HTTP_MOVED_TEMP
            || code == HttpURLConnection.HTTP_SEE_OTHER
            || code == HttpURLConnection.HTTP_MULT_CHOICE
            || code == Constants.HTTP_TEMPORARY_REDIRECT
            || code == Constants.HTTP_PERMANENT_REDIRECT;
}
 
開發者ID:MindorksOpenSource,項目名稱:PRDownloader,代碼行數:8,代碼來源:Utils.java

示例7: unredirect

public static URI unredirect(URI uri) throws IOException {
    if (!REDIRECTOR_DOMAINS.contains(uri.getHost())) {
        return uri;
    }
    URL url = uri.toURL();
    HttpURLConnection connection = safelyOpenConnection(url);
    connection.setInstanceFollowRedirects(false);
    connection.setDoInput(false);
    connection.setRequestMethod("HEAD");
    connection.setRequestProperty("User-Agent", "ZXing (Android)");
    try {
        int responseCode = safelyConnect(connection);
        switch (responseCode) {
            case HttpURLConnection.HTTP_MULT_CHOICE:
            case HttpURLConnection.HTTP_MOVED_PERM:
            case HttpURLConnection.HTTP_MOVED_TEMP:
            case HttpURLConnection.HTTP_SEE_OTHER:
            case 307: // No constant for 307 Temporary Redirect ?
                String location = connection.getHeaderField("Location");
                if (location != null) {
                    try {
                        return new URI(location);
                    } catch (URISyntaxException e) {
                        // nevermind
                    }
                }
        }
        return uri;
    } finally {
        connection.disconnect();
    }
}
 
開發者ID:xiong-it,項目名稱:ZXingAndroidExt,代碼行數:32,代碼來源:HttpHelper.java

示例8: onResponse

/**
 * this method intercepts redirect statusCode and calls {@link #onRedirect(int, String)} methods
 *  if fellowRedirects or followSslRedirects returns false.
 *  
 * this method called by okhttp'callback method ,as a hook method, should be
 * overrode by sub-class,and the sub-class should call super.Response(Call call,Response response)
 * 
 * @param call 		the call 
 * 
 * @param response  the response
 * 
 * @return return false if called {@link #onRedirect(int, String)} ,otherwise return true.
 * */
protected boolean onResponse(Call call, Response response) {
	if(null == okHttpClient){
		throw new NullPointerException("none okHttpClient attached with "+call);
	}
	boolean isFollowRedirects = okHttpClient.followRedirects()
								&&okHttpClient.followSslRedirects();
	System.out.println("isFollowRedirects->"+isFollowRedirects);
	final int statusCode = response.code();
	if ((statusCode == HttpURLConnection.HTTP_MOVED_TEMP 
		|| statusCode == HttpURLConnection.HTTP_MULT_CHOICE 
		|| statusCode == HttpURLConnection.HTTP_MOVED_PERM
		|| statusCode == HttpURLConnection.HTTP_SEE_OTHER)
		&&!isFollowRedirects) {
		String location = response.header("Location");
		System.out.println("header location:"+location);
		if(location == null || location.trim().length() == 0)
		{
			try {
				location = response.body().string();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		final String locationInfo = location;
		OkhttpUtil.getInstance().executeInMainThread(new Runnable() {

			public void run() {
				// TODO Auto-generated method stub
				onRedirect(statusCode, locationInfo);
			}
		});
		return false;
	}
	return true;
}
 
開發者ID:Shelmanxie,項目名稱:okhttpUtil,代碼行數:49,代碼來源:BaseCallback.java

示例9: isHttpRedirect

private static boolean isHttpRedirect(int responseCode) {
    switch (responseCode) {
        case HttpURLConnection.HTTP_MULT_CHOICE:
        case HttpURLConnection.HTTP_MOVED_PERM:
        case HttpURLConnection.HTTP_MOVED_TEMP:
        case HttpURLConnection.HTTP_SEE_OTHER:
        case HTTP_TEMPORARY_REDIRECT:
        case HTTP_PERMANENT_REDIRECT:
            return true;
        default:
            return false;
    }
}
 
開發者ID:tangqipeng,項目名稱:tiny,代碼行數:13,代碼來源:HttpUrlConnectionFetcher.java

示例10: isHttpSuccess

private static boolean isHttpSuccess(int responseCode) {
  return (responseCode >= HttpURLConnection.HTTP_OK &&
      responseCode < HttpURLConnection.HTTP_MULT_CHOICE);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:4,代碼來源:HttpUrlConnectionNetworkFetcher.java

示例11: makeConnection

/**
 * Establishes a connection, following redirects to do so where permitted.
 */
private HttpURLConnection makeConnection(DataSpec dataSpec) throws IOException {
    URL url = new URL(dataSpec.uri.toString());
    byte[] postBody = dataSpec.postBody;
    long position = dataSpec.position;
    long length = dataSpec.length;
    boolean allowGzip = dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_GZIP);

    if (!allowCrossProtocolRedirects) {
        // HttpURLConnection disallows cross-protocol redirects, but otherwise performs redirection
        // automatically. This is the behavior we want, so use it.
        return makeConnection(url, postBody, position, length, allowGzip, true /* followRedirects */);
    }

    // We need to handle redirects ourselves to allow cross-protocol redirects.
    int redirectCount = 0;
    while (redirectCount++ <= MAX_REDIRECTS) {
        HttpURLConnection connection = makeConnection(
                url, postBody, position, length, allowGzip, false /* followRedirects */);
        int responseCode = connection.getResponseCode();
        if (responseCode == HttpURLConnection.HTTP_MULT_CHOICE
                || responseCode == HttpURLConnection.HTTP_MOVED_PERM
                || responseCode == HttpURLConnection.HTTP_MOVED_TEMP
                || responseCode == HttpURLConnection.HTTP_SEE_OTHER
                || (postBody == null
                && (responseCode == 307 /* HTTP_TEMP_REDIRECT */
                || responseCode == 308 /* HTTP_PERM_REDIRECT */))) {
            // For 300, 301, 302, and 303 POST requests follow the redirect and are transformed into
            // GET requests. For 307 and 308 POST requests are not redirected.
            postBody = null;
            String location = connection.getHeaderField("Location");
            connection.disconnect();
            url = handleRedirect(url, location);
        } else {
            return connection;
        }
    }

    // If we get here we've been redirected more times than are permitted.
    throw new NoRouteToHostException("Too many redirects: " + redirectCount);
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:43,代碼來源:CustomHttpDataSource.java

示例12: isSuccessful

private boolean isSuccessful() {
    return responseCode >= HttpURLConnection.HTTP_OK
            && responseCode < HttpURLConnection.HTTP_MULT_CHOICE;
}
 
開發者ID:MindorksOpenSource,項目名稱:PRDownloader,代碼行數:4,代碼來源:DownloadTask.java

示例13: isError

@Override
public boolean isError()
{
	return !((code >= HttpURLConnection.HTTP_OK && code < HttpURLConnection.HTTP_MULT_CHOICE));
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:5,代碼來源:UtilsScriptWrapper.java

示例14: makeConnection

/**
   * Establishes a connection, following redirects to do so where permitted.
   */
// TODO -> make this method protected for all new releases of ExoPlayer
// see Exoplayer Shoutcast patch:
// https://github.com/Ood-Tsen/ExoPlayer/commit/8ccc99bc5c6428760efd9f1780dd90be9386339e
//  private HttpURLConnection makeConnection(DataSpec dataSpec) throws IOException {
  protected HttpURLConnection makeConnection(DataSpec dataSpec) throws IOException {
    URL url = new URL(dataSpec.uri.toString());
    byte[] postBody = dataSpec.postBody;
    long position = dataSpec.position;
    long length = dataSpec.length;
    boolean allowGzip = dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_GZIP);

    if (!allowCrossProtocolRedirects) {
      // HttpURLConnection disallows cross-protocol redirects, but otherwise performs redirection
      // automatically. This is the behavior we want, so use it.
      return makeConnection(url, postBody, position, length, allowGzip, true /* followRedirects */);
    }

    // We need to handle redirects ourselves to allow cross-protocol redirects.
    int redirectCount = 0;
    while (redirectCount++ <= MAX_REDIRECTS) {
      HttpURLConnection connection = makeConnection(
          url, postBody, position, length, allowGzip, false /* followRedirects */);
      int responseCode = connection.getResponseCode();
      if (responseCode == HttpURLConnection.HTTP_MULT_CHOICE
          || responseCode == HttpURLConnection.HTTP_MOVED_PERM
          || responseCode == HttpURLConnection.HTTP_MOVED_TEMP
          || responseCode == HttpURLConnection.HTTP_SEE_OTHER
          || (postBody == null
              && (responseCode == 307 /* HTTP_TEMP_REDIRECT */
                  || responseCode == 308 /* HTTP_PERM_REDIRECT */))) {
        // For 300, 301, 302, and 303 POST requests follow the redirect and are transformed into
        // GET requests. For 307 and 308 POST requests are not redirected.
        postBody = null;
        String location = connection.getHeaderField("Location");
        connection.disconnect();
        url = handleRedirect(url, location);
      } else {
        return connection;
      }
    }

    // If we get here we've been redirected more times than are permitted.
    throw new NoRouteToHostException("Too many redirects: " + redirectCount);
  }
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:47,代碼來源:DefaultHttpDataSource.java


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