本文整理汇总了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;
}
示例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");
}
}
示例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);
}
}
}
}
示例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;
}
示例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();
}
示例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;
}
示例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()]);
}
示例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;
}
示例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());
}
示例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;
}