当前位置: 首页>>代码示例>>Java>>正文


Java HttpURLConnection.getRequestMethod方法代码示例

本文整理汇总了Java中java.net.HttpURLConnection.getRequestMethod方法的典型用法代码示例。如果您正苦于以下问题:Java HttpURLConnection.getRequestMethod方法的具体用法?Java HttpURLConnection.getRequestMethod怎么用?Java HttpURLConnection.getRequestMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.HttpURLConnection的用法示例。


在下文中一共展示了HttpURLConnection.getRequestMethod方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeContent

import java.net.HttpURLConnection; //导入方法依赖的package包/类
/**
 * 得到响应对象
 * 
 * @param urlConnection
 * @return 响应对象
 * @throws IOException
 */
private HttpRespons makeContent(String urlString, HttpURLConnection urlConnection) throws IOException {
	HttpRespons httpResponser = new HttpRespons();
	try {
		InputStream in = urlConnection.getInputStream();
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in,
				Charset.forName(this.defaultContentEncoding)));
		httpResponser.contentCollection = new Vector<String>();
		StringBuffer temp = new StringBuffer();
		String line = bufferedReader.readLine();
		while (line != null) {
			httpResponser.contentCollection.add(line);
			temp.append(line).append("");
			line = bufferedReader.readLine();
		}
		bufferedReader.close();

		String ecod = urlConnection.getContentEncoding();
		if (ecod == null)
			ecod = this.defaultContentEncoding;

		httpResponser.urlString = urlString;

		httpResponser.defaultPort = urlConnection.getURL().getDefaultPort();
		httpResponser.file = urlConnection.getURL().getFile();
		httpResponser.host = urlConnection.getURL().getHost();
		httpResponser.path = urlConnection.getURL().getPath();
		httpResponser.port = urlConnection.getURL().getPort();
		httpResponser.protocol = urlConnection.getURL().getProtocol();
		httpResponser.query = urlConnection.getURL().getQuery();
		httpResponser.ref = urlConnection.getURL().getRef();
		httpResponser.userInfo = urlConnection.getURL().getUserInfo();

		httpResponser.content = temp.toString();
		httpResponser.contentEncoding = ecod;
		httpResponser.code = urlConnection.getResponseCode();
		httpResponser.message = urlConnection.getResponseMessage();
		httpResponser.contentType = urlConnection.getContentType();
		httpResponser.method = urlConnection.getRequestMethod();
		httpResponser.connectTimeout = urlConnection.getConnectTimeout();
		httpResponser.readTimeout = urlConnection.getReadTimeout();

		return httpResponser;
	} catch (IOException e) {
		throw e;
	} finally {
		if (urlConnection != null)
			urlConnection.disconnect();
	}
}
 
开发者ID:butter-fly,项目名称:belling-spring-rabbitmq,代码行数:57,代码来源:HttpRequester.java

示例2: onGetInputStream

import java.net.HttpURLConnection; //导入方法依赖的package包/类
public void onGetInputStream(HttpURLConnection urlConnection, int statusCode) {
  Long startTime = removeObjectProperty(urlConnection, START_TIME_PROPERTY_NAME);
  if (startTime == null) {
    return;
  }

  long t = Clock.defaultClock().getTick() - startTime;
  String method = urlConnection.getRequestMethod();
  String status = "" + statusCode;
  Timer timer = timers.computeIfAbsent(status + method, s -> {
    TagEncodedMetricName metricName = ROOT_NAME.withTags(
        "method", method,
        "status", status);
    return getTimer(metricName);
  });

  timer.update(t, TimeUnit.NANOSECONDS);
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:19,代码来源:UrlConnectionRuleHelper.java

示例3: Entry

import java.net.HttpURLConnection; //导入方法依赖的package包/类
public Entry(URI uri, RawHeaders varyHeaders, HttpURLConnection httpConnection)
    throws IOException {
  this.uri = uri.toString();
  this.varyHeaders = varyHeaders;
  this.requestMethod = httpConnection.getRequestMethod();
  this.responseHeaders = RawHeaders.fromMultimap(httpConnection.getHeaderFields(), true);

  SSLSocket sslSocket = getSslSocket(httpConnection);
  if (sslSocket != null) {
    cipherSuite = sslSocket.getSession().getCipherSuite();
    Certificate[] peerCertificatesNonFinal = null;
    try {
      peerCertificatesNonFinal = sslSocket.getSession().getPeerCertificates();
    } catch (SSLPeerUnverifiedException ignored) {
    }
    peerCertificates = peerCertificatesNonFinal;
    localCertificates = sslSocket.getSession().getLocalCertificates();
  } else {
    cipherSuite = null;
    peerCertificates = null;
    localCertificates = null;
  }
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:24,代码来源:HttpResponseCache.java

示例4: responseReceived

import java.net.HttpURLConnection; //导入方法依赖的package包/类
public void responseReceived(ResponseReceivedEvent event) {
  RequestResult result = event.getRequestResult();
  Date startDate = result.getStartDate();
  Date stopDate = result.getStopDate();
  long elapsed = stopDate.getTime() - startDate.getTime();

  synchronized (this) {
    this.lastE2Elatency = elapsed;
  }

  if (LOG.isDebugEnabled()) {
    int statusCode = result.getStatusCode();
    String etag = result.getEtag();
    HttpURLConnection urlConnection = (HttpURLConnection) event
        .getConnectionObject();
    int contentLength = urlConnection.getContentLength();
    String requestMethod = urlConnection.getRequestMethod();
    long threadId = Thread.currentThread().getId();
    LOG.debug(String
        .format(
            "SelfThrottlingIntercept:: ResponseReceived: threadId=%d, Status=%d, Elapsed(ms)=%d, ETAG=%s, contentLength=%d, requestMethod=%s",
            threadId, statusCode, elapsed, etag, contentLength, requestMethod));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:SelfThrottlingIntercept.java

示例5: createOkResponseForCachePut

import java.net.HttpURLConnection; //导入方法依赖的package包/类
/**
 * Creates an OkHttp {@link Response} using the supplied {@link URI} and {@link URLConnection} to
 * supply the data. The URLConnection is assumed to already be connected. If this method returns
 * {@code null} the response is uncacheable.
 */
public static Response createOkResponseForCachePut(URI uri, URLConnection urlConnection)
    throws IOException {

  HttpURLConnection httpUrlConnection = (HttpURLConnection) urlConnection;

  Response.Builder okResponseBuilder = new Response.Builder();

  // Request: Create one from the URL connection.
  Headers responseHeaders = createHeaders(urlConnection.getHeaderFields());
  // Some request headers are needed for Vary caching.
  Headers varyHeaders = varyHeaders(urlConnection, responseHeaders);
  if (varyHeaders == null) {
    return null;
  }

  // OkHttp's Call API requires a placeholder body; the real body will be streamed separately.
  String requestMethod = httpUrlConnection.getRequestMethod();
  RequestBody placeholderBody = HttpMethod.requiresRequestBody(requestMethod)
      ? Util.EMPTY_REQUEST
      : null;

  Request okRequest = new Request.Builder()
      .url(uri.toString())
      .method(requestMethod, placeholderBody)
      .headers(varyHeaders)
      .build();
  okResponseBuilder.request(okRequest);

  // Status line
  StatusLine statusLine = StatusLine.parse(extractStatusLine(httpUrlConnection));
  okResponseBuilder.protocol(statusLine.protocol);
  okResponseBuilder.code(statusLine.code);
  okResponseBuilder.message(statusLine.message);

  // A network response is required for the Cache to find any Vary headers it needs.
  Response networkResponse = okResponseBuilder.build();
  okResponseBuilder.networkResponse(networkResponse);

  // Response headers
  Headers okHeaders = extractOkResponseHeaders(httpUrlConnection, okResponseBuilder);
  okResponseBuilder.headers(okHeaders);

  // Response body
  ResponseBody okBody = createOkBody(urlConnection);
  okResponseBuilder.body(okBody);

  // Handle SSL handshake information as needed.
  if (httpUrlConnection instanceof HttpsURLConnection) {
    HttpsURLConnection httpsUrlConnection = (HttpsURLConnection) httpUrlConnection;

    Certificate[] peerCertificates;
    try {
      peerCertificates = httpsUrlConnection.getServerCertificates();
    } catch (SSLPeerUnverifiedException e) {
      peerCertificates = null;
    }

    Certificate[] localCertificates = httpsUrlConnection.getLocalCertificates();

    String cipherSuiteString = httpsUrlConnection.getCipherSuite();
    CipherSuite cipherSuite = CipherSuite.forJavaName(cipherSuiteString);
    Handshake handshake = Handshake.get(null, cipherSuite,
        nullSafeImmutableList(peerCertificates), nullSafeImmutableList(localCertificates));
    okResponseBuilder.handshake(handshake);
  }

  return okResponseBuilder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:74,代码来源:JavaApiConverter.java

示例6: createOkResponseForCachePut

import java.net.HttpURLConnection; //导入方法依赖的package包/类
/**
 * Creates an OkHttp {@link Response} using the supplied {@link URI} and {@link URLConnection} to
 * supply the data. The URLConnection is assumed to already be connected. If this method returns
 * {@code null} the response is uncacheable.
 */
public static Response createOkResponseForCachePut(URI uri, URLConnection urlConnection)
    throws IOException {

  HttpURLConnection httpUrlConnection = (HttpURLConnection) urlConnection;

  Response.Builder okResponseBuilder = new Response.Builder();

  // Request: Create one from the URL connection.
  Headers responseHeaders = createHeaders(urlConnection.getHeaderFields());
  // Some request headers are needed for Vary caching.
  Headers varyHeaders = varyHeaders(urlConnection, responseHeaders);
  if (varyHeaders == null) {
    return null;
  }

  // OkHttp's Call API requires a placeholder body; the real body will be streamed separately.
  String requestMethod = httpUrlConnection.getRequestMethod();
  RequestBody placeholderBody = HttpMethod.requiresRequestBody(requestMethod)
      ? Util.EMPTY_REQUEST
      : null;

  Request okRequest = new Request.Builder()
      .url(uri.toString())
      .method(requestMethod, placeholderBody)
      .headers(varyHeaders)
      .build();
  okResponseBuilder.request(okRequest);

  // Status line
  StatusLine statusLine = StatusLine.parse(extractStatusLine(httpUrlConnection));
  okResponseBuilder.protocol(statusLine.protocol);
  okResponseBuilder.code(statusLine.code);
  okResponseBuilder.message(statusLine.message);

  // A network response is required for the Cache to find any Vary headers it needs.
  Response networkResponse = okResponseBuilder.build();
  okResponseBuilder.networkResponse(networkResponse);

  // Response headers
  Headers okHeaders = extractOkResponseHeaders(httpUrlConnection, okResponseBuilder);
  okResponseBuilder.headers(okHeaders);

  // Response body
  ResponseBody okBody = createOkBody(urlConnection);
  okResponseBuilder.body(okBody);

  // Handle SSL handshake information as needed.
  if (httpUrlConnection instanceof HttpsURLConnection) {
    HttpsURLConnection httpsUrlConnection = (HttpsURLConnection) httpUrlConnection;

    Certificate[] peerCertificates;
    try {
      peerCertificates = httpsUrlConnection.getServerCertificates();
    } catch (SSLPeerUnverifiedException e) {
      peerCertificates = null;
    }

    Certificate[] localCertificates = httpsUrlConnection.getLocalCertificates();

    String cipherSuiteString = httpsUrlConnection.getCipherSuite();
    CipherSuite cipherSuite = CipherSuite.forJavaName(cipherSuiteString);
    Handshake handshake = Handshake.get(TlsVersion.SSL_3_0, cipherSuite,
        nullSafeImmutableList(peerCertificates), nullSafeImmutableList(localCertificates));
    okResponseBuilder.handshake(handshake);
  }

  return okResponseBuilder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:74,代码来源:JavaApiConverter.java

示例7: call

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private <T> T call(HttpURLConnection conn, Map jsonOutput,
    int expectedResponse, Class<T> klass, int authRetryCount)
    throws IOException {
  T ret = null;
  try {
    if (jsonOutput != null) {
      writeJson(jsonOutput, conn.getOutputStream());
    }
  } catch (IOException ex) {
    IOUtils.closeStream(conn.getInputStream());
    throw ex;
  }
  if ((conn.getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN
      && (conn.getResponseMessage().equals(ANONYMOUS_REQUESTS_DISALLOWED) ||
          conn.getResponseMessage().contains(INVALID_SIGNATURE)))
      || conn.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
    // Ideally, this should happen only when there is an Authentication
    // failure. Unfortunately, the AuthenticationFilter returns 403 when it
    // cannot authenticate (Since a 401 requires Server to send
    // WWW-Authenticate header as well)..
    KMSClientProvider.this.authToken =
        new DelegationTokenAuthenticatedURL.Token();
    if (authRetryCount > 0) {
      String contentType = conn.getRequestProperty(CONTENT_TYPE);
      String requestMethod = conn.getRequestMethod();
      URL url = conn.getURL();
      conn = createConnection(url, requestMethod);
      conn.setRequestProperty(CONTENT_TYPE, contentType);
      return call(conn, jsonOutput, expectedResponse, klass,
          authRetryCount - 1);
    }
  }
  try {
    AuthenticatedURL.extractToken(conn, authToken);
  } catch (AuthenticationException e) {
    // Ignore the AuthExceptions.. since we are just using the method to
    // extract and set the authToken.. (Workaround till we actually fix
    // AuthenticatedURL properly to set authToken post initialization)
  }
  HttpExceptionUtils.validateResponse(conn, expectedResponse);
  if (conn.getContentType() != null
      && conn.getContentType().trim().toLowerCase()
          .startsWith(APPLICATION_JSON_MIME)
      && klass != null) {
    ObjectMapper mapper = new ObjectMapper();
    InputStream is = null;
    try {
      is = conn.getInputStream();
      ret = mapper.readValue(is, klass);
    } finally {
      IOUtils.closeStream(is);
    }
  }
  return ret;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:56,代码来源:KMSClientProvider.java

示例8: put

import java.net.HttpURLConnection; //导入方法依赖的package包/类
@Override public CacheRequest put(URI uri, URLConnection urlConnection) throws IOException {
  if (!(urlConnection instanceof HttpURLConnection)) {
    return null;
  }

  HttpURLConnection httpConnection = (HttpURLConnection) urlConnection;
  String requestMethod = httpConnection.getRequestMethod();

  if (maybeRemove(requestMethod, uri)) {
    return null;
  }
  if (!requestMethod.equals("GET")) {
    // Don't cache non-GET responses. We're technically allowed to cache
    // HEAD requests and some POST requests, but the complexity of doing
    // so is high and the benefit is low.
    return null;
  }

  HttpEngine httpEngine = getHttpEngine(httpConnection);
  if (httpEngine == null) {
    // Don't cache unless the HTTP implementation is ours.
    return null;
  }

  ResponseHeaders response = httpEngine.getResponseHeaders();
  if (response.hasVaryAll()) {
    return null;
  }

  RawHeaders varyHeaders =
      httpEngine.getRequestHeaders().getHeaders().getAll(response.getVaryFields());
  Entry entry = new Entry(uri, varyHeaders, httpConnection);
  DiskLruCache.Editor editor = null;
  try {
    editor = cache.edit(uriToKey(uri));
    if (editor == null) {
      return null;
    }
    entry.writeTo(editor);
    return new CacheRequestImpl(editor);
  } catch (IOException e) {
    abortQuietly(editor);
    return null;
  }
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:46,代码来源:HttpResponseCache.java


注:本文中的java.net.HttpURLConnection.getRequestMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。