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


Java HttpRequest.getHeaders方法代碼示例

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


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

示例1: execute

import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
private <U, T extends ResponseEnvelope<U>> U execute(final HttpRequest httpRequest, final Class<T> responseType) throws IOException {
   httpRequest.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()));
   if (authToken != null) {
      HttpHeaders headers = httpRequest.getHeaders();
      headers.set("X-Auth-Token", authToken);
   }

   HttpResponse httpResponse = httpRequest.execute();
   T response = httpResponse.parseAs(responseType);

   // Update authToken, if necessary
   if (response.getAuthToken() != null) {
      authToken = response.getAuthToken();
   }

   return response.getData();
}
 
開發者ID:scratch-wireless,項目名稱:kazoo-client,代碼行數:18,代碼來源:KazooConnection.java

示例2: testUserAgent

import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Test
public void testUserAgent() throws IOException {
  when(mockInfoService.getUserAgent()).thenReturn("userAgent");
  Debugger client = CloudDebuggerClient.getLongTimeoutClient("[email protected]");
  HttpRequest httpRequest = client.debuggees().list().buildHttpRequestUsingHead();
  HttpHeaders headers = httpRequest.getHeaders();
  String userAgent = headers.getUserAgent();
  Assert.assertTrue(userAgent.startsWith("userAgent"));
  Assert.assertTrue(userAgent.endsWith("Google-API-Java-Client"));
}
 
開發者ID:GoogleCloudPlatform,項目名稱:google-cloud-intellij,代碼行數:11,代碼來源:CloudDebuggerClientTest.java

示例3: send

import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
/** Uploads {@code reportBytes} to ICANN, returning whether or not it succeeded. */
public boolean send(byte[] reportBytes, String reportFilename) throws XmlException, IOException {
  validateReportFilename(reportFilename);
  GenericUrl uploadUrl = new GenericUrl(makeUrl(reportFilename));
  HttpRequest request =
      httpTransport
          .createRequestFactory()
          .buildPutRequest(uploadUrl, new ByteArrayContent(CSV_UTF_8.toString(), reportBytes));

  HttpHeaders headers = request.getHeaders();
  headers.setBasicAuthentication(getTld(reportFilename) + "_ry", password);
  headers.setContentType(CSV_UTF_8.toString());
  request.setHeaders(headers);
  request.setFollowRedirects(false);

  HttpResponse response = null;
  logger.infofmt(
      "Sending report to %s with content length %s",
      uploadUrl.toString(), request.getContent().getLength());
  boolean success = true;
  try {
    response = request.execute();
    byte[] content;
    try {
      content = ByteStreams.toByteArray(response.getContent());
    } finally {
      response.getContent().close();
    }
    logger.infofmt(
        "Received response code %s with content %s",
        response.getStatusCode(), new String(content, UTF_8));
    XjcIirdeaResult result = parseResult(content);
    if (result.getCode().getValue() != 1000) {
      success = false;
      logger.warningfmt(
          "PUT rejected, status code %s:\n%s\n%s",
          result.getCode(),
          result.getMsg(),
          result.getDescription());
    }
  } finally {
    if (response != null) {
      response.disconnect();
    } else {
      success = false;
      logger.warningfmt(
          "Received null response from ICANN server at %s", uploadUrl.toString());
    }
  }
  return success;
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:52,代碼來源:IcannHttpReporter.java


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