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


Java HttpURLConnection.HTTP_NO_CONTENT属性代码示例

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


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

示例1: perform

@Override
public void perform(
    final Command command, final Log log) throws IOException {
    final String author = command.author();
    final Request follow = command.issue().repo().github().entry()
        .uri().path("/user/following/").path(author).back()
        .method("PUT");
    log.logger().info("Following Github user " + author + " ...");
    try {
        final int status = follow.fetch().status();
        if(status != HttpURLConnection.HTTP_NO_CONTENT) {
            log.logger().error(
                "User follow status response is " + status
                + " . Should have been 204 (NO CONTENT)"
            );
        } else {
            log.logger().info("Followed user " + author + " .");
        }
    } catch (final IOException ex) {
        log.logger().warn("IOException while trying to follow the user.");
    }
    this.next().perform(command, log);
}
 
开发者ID:amihaiemil,项目名称:comdor,代码行数:23,代码来源:FollowUser.java

示例2: call

private boolean call(String methodURL){
	try {
		URL url = new URL(methodURL);
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		String hmac = main.getPublicKey() + "." + main.hmac(methodURL);
		connection.setRequestMethod("DELETE");
		connection.setRequestProperty("User-Agent", "Pterodactyl Java-API");
		connection.setRequestProperty("Authorization", "Bearer " + hmac.replaceAll("\n", ""));
		int responseCode = connection.getResponseCode();
		if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
			return true;
		} else {
			this.lastError = main.readResponse(connection.getErrorStream()).toString();
			return false;
		}
	} catch (Exception e) {
		main.log(Level.SEVERE, e.getMessage());
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:Axeldu18,项目名称:Pterodactyl-JAVA-API,代码行数:21,代码来源:DELETEMethods.java

示例3: assertCached

private void assertCached(boolean shouldPut, int responseCode) throws Exception {
  int expectedResponseCode = responseCode;

  server = new MockWebServer();
  MockResponse mockResponse = new MockResponse()
      .addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS))
      .addHeader("Expires: " + formatDate(1, TimeUnit.HOURS))
      .setResponseCode(responseCode)
      .setBody("ABCDE")
      .addHeader("WWW-Authenticate: challenge");
  if (responseCode == HttpURLConnection.HTTP_PROXY_AUTH) {
    mockResponse.addHeader("Proxy-Authenticate: Basic realm=\"protected area\"");
  } else if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
    mockResponse.addHeader("WWW-Authenticate: Basic realm=\"protected area\"");
  } else if (responseCode == HttpURLConnection.HTTP_NO_CONTENT
      || responseCode == HttpURLConnection.HTTP_RESET) {
    mockResponse.setBody(""); // We forbid bodies for 204 and 205.
  }
  server.enqueue(mockResponse);

  if (responseCode == HttpURLConnection.HTTP_CLIENT_TIMEOUT) {
    // 408's are a bit of an outlier because we may repeat the request if we encounter this
    // response code. In this scenario, there are 2 responses: the initial 408 and then the 200
    // because of the retry. We just want to ensure the initial 408 isn't cached.
    expectedResponseCode = 200;
    server.enqueue(new MockResponse()
        .setHeader("Cache-Control", "no-store")
        .setBody("FGHIJ"));
  }

  server.start();

  URL url = server.url("/").url();
  HttpURLConnection connection = openConnection(url);
  assertEquals(expectedResponseCode, connection.getResponseCode());

  // Exhaust the content stream.
  readAscii(connection);

  CacheResponse cached = cache.get(url.toURI(), "GET", null);
  if (shouldPut) {
    assertNotNull(Integer.toString(responseCode), cached);
  } else {
    assertNull(Integer.toString(responseCode), cached);
  }
  server.shutdown(); // tearDown() isn't sufficient; this test starts multiple servers
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:47,代码来源:ResponseCacheTest.java

示例4: assertCached

private void assertCached(boolean shouldPut, int responseCode) throws Exception {
  int expectedResponseCode = responseCode;

  server = new MockWebServer();
  MockResponse mockResponse = new MockResponse()
      .addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS))
      .addHeader("Expires: " + formatDate(1, TimeUnit.HOURS))
      .setResponseCode(responseCode)
      .setBody("ABCDE")
      .addHeader("WWW-Authenticate: challenge");
  if (responseCode == HttpURLConnection.HTTP_PROXY_AUTH) {
    mockResponse.addHeader("Proxy-Authenticate: Basic realm=\"protected area\"");
  } else if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
    mockResponse.addHeader("WWW-Authenticate: Basic realm=\"protected area\"");
  } else if (responseCode == HttpURLConnection.HTTP_NO_CONTENT
      || responseCode == HttpURLConnection.HTTP_RESET) {
    mockResponse.setBody(""); // We forbid bodies for 204 and 205.
  }
  server.enqueue(mockResponse);

  if (responseCode == HttpURLConnection.HTTP_CLIENT_TIMEOUT) {
    // 408's are a bit of an outlier because we may repeat the request if we encounter this
    // response code. In this scenario, there are 2 responses: the initial 408 and then the 200
    // because of the retry. We just want to ensure the initial 408 isn't cached.
    expectedResponseCode = 200;
    server.enqueue(new MockResponse()
        .setHeader("Cache-Control", "no-store")
        .setBody("FGHIJ"));
  }

  server.start();

  Request request = new Request.Builder()
      .url(server.url("/"))
      .build();
  Response response = client.newCall(request).execute();
  assertEquals(expectedResponseCode, response.code());

  // Exhaust the content stream.
  response.body().string();

  Response cached = cache.get(request);
  if (shouldPut) {
    assertNotNull(Integer.toString(responseCode), cached);
    cached.body().close();
  } else {
    assertNull(Integer.toString(responseCode), cached);
  }
  server.shutdown(); // tearDown() isn't sufficient; this test starts multiple servers
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:50,代码来源:CacheTest.java

示例5: assertCached

private void assertCached(boolean shouldPut, int responseCode) throws Exception {
  int expectedResponseCode = responseCode;

  server = new MockWebServer();
  MockResponse response = new MockResponse()
      .addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS))
      .addHeader("Expires: " + formatDate(1, TimeUnit.HOURS))
      .setResponseCode(responseCode)
      .setBody("ABCDE")
      .addHeader("WWW-Authenticate: challenge");
  if (responseCode == HttpURLConnection.HTTP_PROXY_AUTH) {
    response.addHeader("Proxy-Authenticate: Basic realm=\"protected area\"");
  } else if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
    response.addHeader("WWW-Authenticate: Basic realm=\"protected area\"");
  } else if (responseCode == HttpURLConnection.HTTP_NO_CONTENT
      || responseCode == HttpURLConnection.HTTP_RESET) {
    response.setBody(""); // We forbid bodies for 204 and 205.
  }
  server.enqueue(response);

  if (responseCode == HttpURLConnection.HTTP_CLIENT_TIMEOUT) {
    // 408's are a bit of an outlier because we may repeat the request if we encounter this
    // response code. In this scenario, there are 2 responses: the initial 408 and then the 200
    // because of the retry. We just want to ensure the initial 408 isn't cached.
    expectedResponseCode = 200;
    server.enqueue(new MockResponse()
        .addHeader("Cache-Control", "no-store")
        .setBody("FGHIJ"));
  }

  server.start();

  URL url = server.url("/").url();
  HttpURLConnection conn = urlFactory.open(url);
  assertEquals(expectedResponseCode, conn.getResponseCode());

  // exhaust the content stream
  readAscii(conn);

  Response cached = cache.get(new Request.Builder().url(url).build());
  if (shouldPut) {
    assertNotNull(Integer.toString(responseCode), cached);
    cached.body().close();
  } else {
    assertNull(Integer.toString(responseCode), cached);
  }
  server.shutdown(); // tearDown() isn't sufficient; this test starts multiple servers
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:48,代码来源:UrlConnectionCacheTest.java

示例6: isConnected

protected Boolean isConnected(final String host, final int port, final int timeoutInMs,
                              final ErrorHandler errorHandler) {
    HttpURLConnection urlConnection = null;
    try {
        urlConnection = createHttpUrlConnection(host, port, timeoutInMs);
        return urlConnection.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT;
    } catch (IOException e) {
        errorHandler.handleError(e, "Could not establish connection with WalledGardenStrategy");
        return Boolean.FALSE;
    } finally {
        if (urlConnection != null) {
            urlConnection.disconnect();
        }
    }
}
 
开发者ID:datalink747,项目名称:Rx_java2_soussidev,代码行数:15,代码来源:WalledGardenInternetObservingStrategy.java

示例7: act

@Override
public Response act(Request req) throws IOException {
    long categoryId = Long.parseLong(((RqRegex) req).matcher().group("ctgId"));
    long productId = Long.parseLong(((RqRegex) req).matcher().group("prdId"));
    Category category = base.categories().category(categoryId);
    Product product = base.products().product(productId);

    base.categoryProducts(category).remove(product);

    return new RsWithStatus(HttpURLConnection.HTTP_NO_CONTENT);
}
 
开发者ID:yaroska,项目名称:true_oop,代码行数:11,代码来源:TkCategoryProductDelete.java

示例8: act

@Override
public Response act(Request req) throws IOException {
    long categoryId = Long.parseLong(((RqRegex) req).matcher().group("number"));
    Category category = base.categories().category(categoryId);
    JsonReader reader = Json.createReader(req.body());
    Product[] products = reader.readArray().stream()
            .map(JsonValue::asJsonObject)
            .map(product -> product.getInt("id"))
            .map(id -> base.products().product(id))
            .toArray(Product[]::new);
    base.categoryProducts(category).add(products);
    return new RsWithStatus(HttpURLConnection.HTTP_NO_CONTENT);
}
 
开发者ID:yaroska,项目名称:true_oop,代码行数:13,代码来源:TkCategoryProductsAdd.java

示例9: act

@Override
public Response act(Request req) throws IOException {
    long categoryId = Long.parseLong(((RqRegex) req).matcher().group("ctgId"));
    long productId = Long.parseLong(((RqRegex) req).matcher().group("prdId"));
    Category category = base.categories().category(categoryId);
    Product product = base.products().product(productId);

    base.categoryProducts(category).add(product);

    return new RsWithStatus(HttpURLConnection.HTTP_NO_CONTENT);
}
 
开发者ID:yaroska,项目名称:true_oop,代码行数:11,代码来源:TkCategoryProductAdd.java

示例10: act

@Override
public Response act(Request req) throws IOException {
    long number = Long.parseLong(((RqRegex) req).matcher().group("number"));
    Product product = base.products().product(number);

    base.products().delete(product);
    return new RsWithStatus(HttpURLConnection.HTTP_NO_CONTENT);
}
 
开发者ID:yaroska,项目名称:true_oop,代码行数:8,代码来源:TkProductDelete.java

示例11: act

@Override
public Response act(Request req) throws IOException {
    long number = Long.parseLong(((RqRegex) req).matcher().group("number"));
    Category category = base.categories().category(number);

    base.categories().delete(category);
    return new RsWithStatus(HttpURLConnection.HTTP_NO_CONTENT);
}
 
开发者ID:yaroska,项目名称:true_oop,代码行数:8,代码来源:TkCategoryDelete.java

示例12: parseResponse

private AvsResponse parseResponse() throws IOException, AvsException, RuntimeException {

        Request request = mRequestBuilder.build();


        currentCall = ClientUtil.getTLS12OkHttpClient().newCall(request);

        try {
            Response response = currentCall.execute();

            if(response.code() == HttpURLConnection.HTTP_NO_CONTENT){
                Log.w(TAG, "Received a 204 response code from Amazon, is this expected?");
            }

            final AvsResponse val = response.code() == HttpURLConnection.HTTP_NO_CONTENT ? new AvsResponse() :
                    ResponseParser.parseResponse(response.body().byteStream(), getBoundary(response));

            response.body().close();

            return val;
        } catch (IOException exp) {
            if (!currentCall.isCanceled()) {
                return new AvsResponse();
            }
        }
        return null;
    }
 
开发者ID:vaibhavs4424,项目名称:AI-Powered-Intelligent-Banking-Platform,代码行数:27,代码来源:SendEvent.java

示例13: dispatch

@VisibleForTesting
public boolean dispatch(@NonNull final Packet packet) {
    // Some error checking
    if (packet.getTargetURL() == null)
        return false;
    if (packet.getJSONObject() != null && packet.getJSONObject().length() == 0)
        return false;

    if (mPiwik.isDryRun()) {
        mDryRunOutput.add(packet);
        Timber.tag(LOGGER_TAG).d("DryRun, stored HttpRequest, now %s.", mDryRunOutput.size());
        return true;
    }

    if (!mDryRunOutput.isEmpty())
        mDryRunOutput.clear();

    try {

        StrongOkHttpClientBuilder builder= StrongOkHttpClientBuilder.forMaxSecurity(mPiwik.getContext());

        OkHttpClient client = null;

        if (mCertPin != null) {
            CertificatePinner certificatePinner = new CertificatePinner.Builder()
                    .add(packet.getTargetURL().getHost(), mCertPin)
                    .build();

                client = new OkHttpClient.Builder()
                        .proxy(mProxy)
                    .certificatePinner(certificatePinner)
                    .build();
        }
        else
        {
            client = new OkHttpClient.Builder()
                    .proxy(mProxy)
                    .build();
        }

        Request request = null;

        // IF there is json data we want to do a post
        if (packet.getJSONObject() != null) {

            MediaType JSON
                    = MediaType.parse("application/json; charset=utf-8");


            RequestBody body = RequestBody.create(JSON, packet.getJSONObject().toString());
            request = new Request.Builder()
                    .url(packet.getTargetURL())
                    .post(body)
                    .build();

        } else {
            // GET
            request = new Request.Builder()
                    .url(packet.getTargetURL())
                    .build();
        }

        Response response = client.newCall(request).execute();

        int statusCode = response.code();
        Timber.tag(LOGGER_TAG).d("status code %s", statusCode);


        return statusCode == HttpURLConnection.HTTP_NO_CONTENT || statusCode == HttpURLConnection.HTTP_OK;
    } catch (Exception e) {
        // Broad but an analytics app shouldn't impact it's host app.
        Timber.tag(LOGGER_TAG).w(e, "Cannot send request");
    }
    return false;
}
 
开发者ID:cleaninsights,项目名称:cleaninsights-android-sdk,代码行数:75,代码来源:Dispatcher.java


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