com.google.appengine.api.urlfetch.HTTPResponse.getContent()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(84)

本文整理了Java中com.google.appengine.api.urlfetch.HTTPResponse.getContent()方法的一些代码示例,展示了HTTPResponse.getContent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HTTPResponse.getContent()方法的具体详情如下:
包路径:com.google.appengine.api.urlfetch.HTTPResponse
类名称:HTTPResponse
方法名:getContent

HTTPResponse.getContent介绍

暂无

代码示例

代码示例来源:origin: googlemaps/google-maps-services-java

byte[] bytes = response.getContent();
R resp;
      "Server Error: %d %s",
      response.getResponseCode(),
      new String(response.getContent(), Charset.defaultCharset())));

代码示例来源:origin: com.google.http-client/google-http-client-extensions

@Override
public InputStream getContent() {
 byte[] content = fetchResponse.getContent();
 return content == null ? null : new ByteArrayInputStream(content);
}

代码示例来源:origin: com.google.http-client/google-http-client-appengine

@Override
public InputStream getContent() {
 byte[] content = fetchResponse.getContent();
 return content == null ? null : new ByteArrayInputStream(content);
}

代码示例来源:origin: com.threewks.thundr/thundr-gae

@Override
public InputStream getBodyAsStream() {
  byte[] content = response().getContent();
  content = content == null ? new byte[0] : content;
  return new ByteArrayInputStream(content);
}

代码示例来源:origin: stackoverflow.com

URL url = new URL(request);
   HTTPRequest req = new HTTPRequest(url, HTTPMethod.GET);
   req.addHeader(new HTTPHeader("Authorization", "Bearer " + bearerToken));
   HTTPResponse response = URLFetchServiceFactory.getURLFetchService().fetch(req);
   System.out.println(new String(response.getContent()));

代码示例来源:origin: com.threewks.thundr/thundr-gae

@Override
public byte[] getBodyAsBytes() {
  return response().getContent();
}

代码示例来源:origin: stackoverflow.com

//Classes to import
import com.google.appengine.api.urlfetch.HTTPMethod;
import com.google.appengine.api.urlfetch.HTTPRequest;
import com.google.appengine.api.urlfetch.HTTPResponse;
import com.google.appengine.api.urlfetch.URLFetchService;
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;

//Shortening download URL
URL url=new URL("http://goo.gl/api/shorten");
HTTPRequest req=new HTTPRequest(url,HTTPMethod.POST);                               
req.setPayload(("url=www.google.com").getBytes());

URLFetchService  service = URLFetchServiceFactory.getURLFetchService(); 
HTTPResponse response = service.fetch(req); 
byte[] content = response.getContent(); 
String urlshort=new String(content);   //here is the JSON data from goo.gl

代码示例来源:origin: org.apache.camel/camel-gae

protected void readResponseBody(GHttpEndpoint endpoint, Exchange exchange, HTTPResponse response) throws Exception {
  byte[] content = response.getContent();
  if (content != null) {
    InputStream stream = new ByteArrayInputStream(content);
    if (isGzip(getResponseHeader("Content-Encoding", response))) {
      stream = new GZIPInputStream(stream);
    }
    exchange.getOut().setBody(stream);
  }
}

代码示例来源:origin: jgritman/httpbuilder

public void receiveResponseEntity(HttpResponse response)
 throws HttpException, IOException {
 if (this.response == null) {
  throw new IOException("receiveResponseEntity() called on closed connection");
 }
 ByteArrayEntity bae = new ByteArrayEntity(this.response.getContent());
 bae.setContentType(response.getFirstHeader("Content-Type"));
 response.setEntity(bae);
 response = null;
}

代码示例来源:origin: org.codehaus.groovy.modules.http-builder/http-builder

public void receiveResponseEntity(HttpResponse response)
 throws HttpException, IOException {
 if (this.response == null) {
  throw new IOException("receiveResponseEntity() called on closed connection");
 }
 ByteArrayEntity bae = new ByteArrayEntity(this.response.getContent());
 bae.setContentType(response.getFirstHeader("Content-Type"));
 response.setEntity(bae);
 response = null;
}

代码示例来源:origin: GoogleCloudPlatform/appengine-gcs-client

static void appendResponse(HTTPResponse resp, StringBuilder b) {
 byte[] content = resp.getContent();
 b.append(resp.getResponseCode()).append(" with ").append(content == null ? 0 : content.length);
 b.append(" bytes of content");
 for (HTTPHeader h : resp.getHeadersUncombined()) {
  b.append('\n').append(h.getName()).append(": ").append(h.getValue());
 }
 b.append('\n').append(content == null ? "" : new String(content, UTF_8)).append('\n');
}

代码示例来源:origin: stackoverflow.com

URL fetchurl = new URL(url);

String nameAndPassword = credentials.get("name")+":"+credentials.get("password");
String authorizationString = "Basic " + Base64.encode(nameAndPassword.getBytes());

HTTPRequest request = new HTTPRequest(fetchurl);
request.addHeader(new HTTPHeader("Authorization", authorizationString));

HTTPResponse response = URLFetchServiceFactory.getURLFetchService().fetch(request);
System.out.println(new String(response.getContent()));

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

protected void printResponse(HTTPResponse response) throws Exception {
  System.out.println("response = " + new String(response.getContent()));
}

代码示例来源:origin: com.dropbox.core/dropbox-core-sdk

private static Response toRequestorResponse(HTTPResponse response) {
  Map<String, List<String>> headers = new HashMap<String, List<String>>();
  for (HTTPHeader header : response.getHeadersUncombined()) {
    List<String> existing = headers.get(header.getName());
    if (existing == null) {
      existing = new ArrayList<String>();
      headers.put(header.getName(), existing);
    }
    existing.add(header.getValue());
  }
  return new Response(response.getResponseCode(),
            new ByteArrayInputStream(response.getContent()),
            headers);
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test
void testConvertWithHeaders() throws IOException {
 HTTPResponse gaeResponse = createMock(HTTPResponse.class);
 expect(gaeResponse.getResponseCode()).andReturn(200);
 List<HTTPHeader> headers = Lists.newArrayList();
 headers.add(new HTTPHeader(HttpHeaders.CONTENT_TYPE, "text/xml"));
 expect(gaeResponse.getHeaders()).andReturn(headers);
 expect(gaeResponse.getContent()).andReturn(null).atLeastOnce();
 replay(gaeResponse);
 HttpResponse response = req.apply(gaeResponse);
 assertEquals(response.getStatusCode(), 200);
 assertEquals(response.getPayload(), null);
 assertEquals(response.getHeaders().size(), 0);
}

代码示例来源:origin: apache/jclouds

@Test
void testConvertWithHeaders() throws IOException {
 HTTPResponse gaeResponse = createMock(HTTPResponse.class);
 expect(gaeResponse.getResponseCode()).andReturn(200);
 List<HTTPHeader> headers = Lists.newArrayList();
 headers.add(new HTTPHeader(HttpHeaders.CONTENT_TYPE, "text/xml"));
 expect(gaeResponse.getHeaders()).andReturn(headers);
 expect(gaeResponse.getContent()).andReturn(null).atLeastOnce();
 replay(gaeResponse);
 HttpResponse response = req.apply(gaeResponse);
 assertEquals(response.getStatusCode(), 200);
 assertEquals(response.getPayload(), null);
 assertEquals(response.getHeaders().size(), 0);
}

代码示例来源:origin: jclouds/legacy-jclouds

@Test
void testConvertWithContent() throws IOException {
 HTTPResponse gaeResponse = createMock(HTTPResponse.class);
 expect(gaeResponse.getResponseCode()).andReturn(200);
 List<HTTPHeader> headers = Lists.newArrayList();
 headers.add(new HTTPHeader(HttpHeaders.CONTENT_TYPE, "text/xml"));
 expect(gaeResponse.getHeaders()).andReturn(headers);
 expect(gaeResponse.getContent()).andReturn("hello".getBytes()).atLeastOnce();
 replay(gaeResponse);
 HttpResponse response = req.apply(gaeResponse);
 assertEquals(response.getStatusCode(), 200);
 assertEquals(Strings2.toString(response.getPayload()), "hello");
 assertEquals(response.getHeaders().size(), 0);
 assertEquals(response.getPayload().getContentMetadata().getContentType(), "text/xml");
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

protected String fetchUrl(String url, int expectedResponse) throws IOException {
  URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService();
  HTTPResponse httpResponse = urlFetchService.fetch(new URL(url));
  assertEquals(url, expectedResponse, httpResponse.getResponseCode());
  return new String(httpResponse.getContent());
}

代码示例来源:origin: apache/jclouds

@Test
void testConvertWithContent() throws IOException {
 HTTPResponse gaeResponse = createMock(HTTPResponse.class);
 expect(gaeResponse.getResponseCode()).andReturn(200);
 List<HTTPHeader> headers = Lists.newArrayList();
 headers.add(new HTTPHeader(HttpHeaders.CONTENT_TYPE, "text/xml"));
 expect(gaeResponse.getHeaders()).andReturn(headers);
 expect(gaeResponse.getContent()).andReturn("hello".getBytes()).atLeastOnce();
 replay(gaeResponse);
 HttpResponse response = req.apply(gaeResponse);
 assertEquals(response.getStatusCode(), 200);
 assertEquals(Strings2.toStringAndClose(response.getPayload().openStream()), "hello");
 assertEquals(response.getHeaders().size(), 0);
 assertEquals(response.getPayload().getContentMetadata().getContentType(), "text/xml");
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testPayload() throws Exception {
  URLFetchService service = URLFetchServiceFactory.getURLFetchService();
  URL url = getFetchUrl();
  HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST);
  req.setHeader(new HTTPHeader("Content-Type", "application/octet-stream"));
  req.setPayload("Tralala".getBytes(UTF_8));
  HTTPResponse response = service.fetch(req);
  String content = new String(response.getContent());
  Assert.assertEquals("Hopsasa", content);
}

相关文章