本文整理了Java中com.google.api.client.http.HttpRequest.setContent()
方法的一些代码示例,展示了HttpRequest.setContent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.setContent()
方法的具体详情如下:
包路径:com.google.api.client.http.HttpRequest
类名称:HttpRequest
方法名:setContent
暂无
代码示例来源:origin: org.eclipse.scout.rt/org.eclipse.scout.rt.server.commons
protected void writeRequestPayload(HttpServletRequest req, HttpRequest httpReq) throws IOException {
httpReq.setContent(new InputStreamContent(null, req.getInputStream()));
}
代码示例来源:origin: org.eclipse.scout.rt/org.eclipse.scout.rt.server.commons
protected void writeRequestParameters(HttpServletRequest req, HttpRequest httpReq) throws IOException {
String parameters = formatFormParameters(req.getParameterMap());
httpReq.setContent(new InputStreamContent(null, new ByteArrayInputStream(parameters.getBytes(StandardCharsets.UTF_8))));
}
代码示例来源:origin: com.google.api-client/google-api-client
/**
* {@link Beta} <br/>
* The call back method that will be invoked on a server error or an I/O exception during
* resumable upload inside {@link #upload}.
*
* <p>
* This method changes the current request to query the current status of the upload to find how
* many bytes were successfully uploaded before the server error occurred.
* </p>
*/
@Beta
void serverErrorCallback() throws IOException {
Preconditions.checkNotNull(currentRequest, "The current request should not be null");
// Query the current status of the upload by issuing an empty PUT request on the upload URI.
currentRequest.setContent(new EmptyContent());
currentRequest.getHeaders().setContentRange("bytes */" + mediaContentLengthStr);
}
代码示例来源:origin: com.google.api-client/google-api-client
public void intercept(HttpRequest request) throws IOException {
if (overrideThisMethod(request)) {
String requestMethod = request.getRequestMethod();
request.setRequestMethod(HttpMethods.POST);
request.getHeaders().set(HEADER, requestMethod);
if (requestMethod.equals(HttpMethods.GET)) {
// take the URI query part and put it into the HTTP body
request.setContent(new UrlEncodedContent(request.getUrl().clone()));
// remove query parameters from URI
request.getUrl().clear();
} else if (request.getContent() == null) {
// Google servers will fail to process a POST unless the Content-Length header is specified
request.setContent(new EmptyContent());
}
}
}
代码示例来源:origin: com.google.api-client/google-api-client
httpRequest.setContent(new EmptyContent());
代码示例来源:origin: googleads/googleads-java-lib
@Test
public void testNoResponseBodySet_fails() throws IOException {
HttpRequest request =
mockHttpServer
.getHttpTransport()
.createRequestFactory()
.buildGetRequest(new GenericUrl(mockHttpServer.getServerUrl()));
request.setContent(new ByteArrayContent("text", "test content".getBytes(UTF_8)));
thrown.expect(HttpResponseException.class);
thrown.expectMessage("No mock response");
request.execute();
}
代码示例来源:origin: siom79/jdrivesync
httpRequest.setContent(fileContent);
HttpResponse httpResponse;
try {
代码示例来源:origin: siom79/jdrivesync
httpRequest.setContent(fileContent);
HttpResponse httpResponse = null;
try {
代码示例来源:origin: com.google.api-client/google-api-client
new HttpRequestContent(requestInfo.request)));
batchRequest.setContent(batchContent);
HttpResponse response = batchRequest.execute();
BatchUnparsedResponse batchResponse;
代码示例来源:origin: googleads/googleads-java-lib
/**
* Tests behavior when URL validation is enabled and the URL of the request does not match the
* server's URL.
*/
@Test
public void testUrlMismatch_fails() throws IOException {
HttpRequest request =
mockHttpServer
.getHttpTransport()
.createRequestFactory()
.buildGetRequest(
new GenericUrl("http://www.example.com/does_not_match_mock_http_server_url"));
request.setContent(new ByteArrayContent("text", "test content".getBytes(UTF_8)));
mockHttpServer.setMockResponse(new MockResponse("test response"));
thrown.expect(ConnectException.class);
request.execute();
}
代码示例来源:origin: com.google.api-client/google-api-client
ContentChunk contentChunk = buildContentChunk();
currentRequest = requestFactory.buildPutRequest(uploadUrl, null);
currentRequest.setContent(contentChunk.getContent());
currentRequest.getHeaders().setContentRange(contentChunk.getContentRange());
代码示例来源:origin: spotify/async-google-pubsub-client
headers.setContentLength((long) json.length);
headers.setContentType(APPLICATION_JSON_UTF8);
request.setContent(new ByteArrayContent(APPLICATION_JSON_UTF8, json));
} else {
payloadSize = 0;
代码示例来源:origin: googleads/googleads-java-lib
.buildGetRequest(new GenericUrl(mockHttpServer.getServerUrl()));
String requestContent = "test request";
request.setContent(new ByteArrayContent("text", requestContent.getBytes(UTF_8)));
代码示例来源:origin: googleads/googleads-java-lib
/**
* Tests behavior when URL validation is disabled.
*/
@Test
public void testUrlMismatch_verifyDisabled() throws IOException {
MockResponse mockResponse = new MockResponse("test response");
mockResponse.setValidateUrlMatches(false);
HttpRequest request =
mockHttpServer
.getHttpTransport()
.createRequestFactory()
.buildGetRequest(
new GenericUrl("http://www.example.com/does_not_match_mock_http_server_url"));
request.setContent(new ByteArrayContent("text", "test content".getBytes(UTF_8)));
HttpHeaders headers = new HttpHeaders();
headers.set("one", "1");
headers.set("two", "2");
request.setHeaders(headers);
mockHttpServer.setMockResponse(mockResponse);
HttpResponse response = request.execute();
ActualResponse actualResponse = mockHttpServer.getLastResponse();
assertEquals("Incorrect response code", 200, response.getStatusCode());
assertEquals(
"Request header 'one' incorrect", "1", actualResponse.getRequestHeader("one").get(0));
assertEquals(
"Request header 'two' incorrect", "2", actualResponse.getRequestHeader("two").get(0));
}
内容来源于网络,如有侵权,请联系作者删除!