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


Java HTTPResponse.getHeaders方法代码示例

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


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

示例1: getCharset

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
private static String getCharset(HTTPResponse p_response)
{
  String responseCharset = "UTF-8";


  for( HTTPHeader header : p_response.getHeaders() )
  {
    if( "Content-Type".equalsIgnoreCase( header.getName() ) )
    {
      Matcher matcher = s_charsetPattern.matcher( header.getValue() );
      if( matcher.matches() )
      {
        responseCharset = matcher.group( 1 );
      }
    }
  }
  return responseCharset;
}
 
开发者ID:kroc702,项目名称:fullmetalgalaxy,代码行数:19,代码来源:ConectorImpl.java

示例2: doGet

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws IOException, ServletException {
  String url = req.getParameter("url");
  String deadlineSecs = req.getParameter("deadline");
  URLFetchService service = URLFetchServiceFactory.getURLFetchService();
  HTTPRequest fetchReq = new HTTPRequest(new URL(url));
  if (deadlineSecs != null) {
    fetchReq.getFetchOptions().setDeadline(Double.valueOf(deadlineSecs));
  }
  HTTPResponse fetchRes = service.fetch(fetchReq);
  for (HTTPHeader header : fetchRes.getHeaders()) {
    res.addHeader(header.getName(), header.getValue());
  }
  if (fetchRes.getResponseCode() == 200) {
    res.getOutputStream().write(fetchRes.getContent());
  } else {
    res.sendError(fetchRes.getResponseCode(), "Error while fetching");
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:20,代码来源:CurlServlet.java

示例3: updateCookies

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
private void updateCookies(HTTPResponse resp) {
	if(sessionParam!=null) return; // don't use cookies with anonymous sessions
	List<HTTPHeader> headers = resp.getHeaders();
	Collection<HTTPHeader> cookies = Collections2.filter(headers, new Predicate<HTTPHeader>() {
		@Override
		public boolean apply(HTTPHeader header) {
			return header.getName().equalsIgnoreCase("Set-Cookie");
		}
	});
	if(!cookies.isEmpty()) {
		logCookies(cookies);
		HTTPHeader setcookie = cookies.iterator().next();
		String[] values = setcookie.getValue().split(";");
		if(values.length>0) {
			String value = values[0];
			if(value.split("=")[0].equalsIgnoreCase("jsessionid")) { 
				// only update jsessionid cookies
				cookie = new HTTPHeader("Cookie", value);
			}
		}
	}
}
 
开发者ID:marcusschiesser,项目名称:openbahn-api,代码行数:23,代码来源:HTTPSession.java

示例4: describeResponse

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
private String describeResponse(HTTPResponse resp, boolean includeBody) {
  StringBuilder b = new StringBuilder(resp.getResponseCode()
      + " with " + resp.getContent().length + " bytes of content");
  for (HTTPHeader h : resp.getHeaders()) {
    b.append("\n" + h.getName() + ": " + h.getValue());
  }
  if (includeBody) {
    b.append("\n" + new String(resp.getContent(), Charsets.UTF_8));
  } else {
    b.append("\n<content elided>");
  }
  return "" + b;
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:14,代码来源:OAuthedFetchService.java

示例5: getHeaders

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
/** Gets the values of all headers with the name {@code headerName}. */
public static List<String> getHeaders(HTTPResponse resp, String headerName) {
  ImmutableList.Builder<String> b = ImmutableList.builder();
  for (HTTPHeader h : resp.getHeaders()) {
    // HTTP header names are case-insensitive.  App Engine downcases them when
    // deployed but not when running locally.
    if (headerName.equalsIgnoreCase(h.getName())) {
      b.add(h.getValue());
    }
  }
  return b.build();
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:13,代码来源:OAuthedFetchService.java

示例6: describeResponse

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
private String describeResponse(HTTPResponse resp) {
  StringBuilder b = new StringBuilder(resp.getResponseCode()
      + " with " + resp.getContent().length + " bytes of content");
  for (HTTPHeader h : resp.getHeaders()) {
    b.append("\n" + h.getName() + ": " + h.getValue());
  }
  b.append("\n" + new String(resp.getContent(), Charsets.UTF_8));
  return "" + b;
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:10,代码来源:AffinityMutationProcessor.java

示例7: getResponseHeaders

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
private static Header[] getResponseHeaders(HTTPResponse httpResponse, String headerName) {
  List<HTTPHeader> allHeaders = httpResponse.getHeaders();
  List<Header> matchingHeaders = new ArrayList<Header>();
  for (HTTPHeader header : allHeaders) {
    if (header.getName().equalsIgnoreCase(headerName)) {
      matchingHeaders.add(new BasicHeader(header.getName(), header.getValue()));
    }
  }
  return matchingHeaders.toArray(new Header[matchingHeaders.size()]);
}
 
开发者ID:jbufu,项目名称:openid4java,代码行数:11,代码来源:AppEngineHttpFetcher.java

示例8: describeResponse

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
private String describeResponse(HTTPResponse resp) {
  StringBuilder b =
      new StringBuilder(resp.getResponseCode() + " with " + resp.getContent().length
          + " bytes of content");
  for (HTTPHeader h : resp.getHeaders()) {
    b.append("\n" + h.getName() + ": " + h.getValue());
  }
  b.append("\n" + new String(resp.getContent(), Charsets.UTF_8));
  return "" + b;
}
 
开发者ID:larrytin,项目名称:realtime-server-appengine,代码行数:11,代码来源:AffinityMutationProcessor.java

示例9: copyResponse

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
public static void copyResponse(HTTPResponse from, HttpServletResponse to) throws IOException {
  to.setStatus(from.getResponseCode());
  for (HTTPHeader header : from.getHeaders()) {
    to.setHeader(header.getName(), header.getValue());
  }
  copy(new ByteArrayInputStream(from.getContent()), to.getOutputStream());
}
 
开发者ID:larrytin,项目名称:realtime-server-appengine,代码行数:8,代码来源:ProxyHandler.java

示例10: sendMessageToCryptonomicaAdminsChat

import com.google.appengine.api.urlfetch.HTTPResponse; //导入方法依赖的package包/类
public static HTTPResponse sendMessageToCryptonomicaAdminsChat(final String message) {

        final String CryptonomicaBotToken = ApiKeysUtils.getApiKey("CryptonomicaBotToken");

        final String urlAddress = "https://api.telegram.org/bot" + CryptonomicaBotToken + "/sendMessage";

        final String cryptonomicaAdminsChatId = ApiKeysUtils.getApiKey("cryptonomicaAdminsChatId");

        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("chat_id", cryptonomicaAdminsChatId);
        parameterMap.put("text", message);

        // https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/urlfetch/HTTPResponse
        //
        HTTPResponse httpResponse = HttpService.makePostRequestWithParametersMap(urlAddress, parameterMap);

        byte[] httpResponseContentBytes = httpResponse.getContent();
        String httpResponseContentString = null;
        if (httpResponseContentBytes != null) {
            httpResponseContentString = new String(httpResponseContentBytes, StandardCharsets.UTF_8);

            LOG.warning(
                    "httpResponse.getFinalUrl() : " + httpResponse.getFinalUrl() + "\n"
                            + "httpResponse.getResponseCode(): " + httpResponse.getResponseCode() + "\n"
                            + "httpResponse.getContent(): " + httpResponseContentString + "\n"
            );
            LOG.warning("headers: ");
            for (HTTPHeader httpHeader : httpResponse.getHeaders()) {
                String headerName = httpHeader.getName();
                String headerValue = httpHeader.getValue();
                LOG.warning(headerName + " : " + headerValue);
            }

        } else {
            LOG.severe(
                    "httpResponse.getContent() is null"
            );
        }

        return httpResponse;
    }
 
开发者ID:Cryptonomica,项目名称:cryptonomica,代码行数:42,代码来源:CryptonomicaBot.java


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