本文整理了Java中org.apache.http.client.fluent.Request.Post
方法的一些代码示例,展示了Request.Post
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.Post
方法的具体详情如下:
包路径:org.apache.http.client.fluent.Request
类名称:Request
方法名:Post
暂无
代码示例来源:origin: twosigma/beakerx
@Override
public String update(String name, String json) {
try {
String reply = Request.Post(LOCALHOST + this.context.getPort() + AUTOTRANSLTION)
.addHeader(AUTHORIZATION, auth())
.bodyString(createBody(name, json), ContentType.APPLICATION_JSON)
.execute().returnContent().asString();
if (!reply.equals("ok")) {
throw new RuntimeException(reply);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return json;
}
代码示例来源:origin: dreamhead/moco
public String postBytes(final String url, final byte[] bytes, final Charset charset) throws IOException {
return executeAsString(Request.Post(url)
.bodyByteArray(bytes, ContentType.create("text/plain", charset)));
}
代码示例来源:origin: dreamhead/moco
@Override
public void run() throws Exception {
org.apache.http.client.fluent.Request request = Post(root()).bodyForm(of(new BasicNameValuePair("name", "表单")), Charset.forName("GBK"));
assertThat(helper.executeAsString(request), is("foobar"));
}
});
代码示例来源:origin: dreamhead/moco
public HttpResponse postForResponse(final String url, final String content, final String contentType)
throws IOException {
return execute(Request.Post(url)
.addHeader(CONTENT_TYPE, contentType)
.bodyByteArray(content.getBytes()));
}
代码示例来源:origin: dreamhead/moco
@Override
public void run() throws Exception {
Request request = Request.Post(root()).bodyForm(new BasicNameValuePair("name", "dreamhead"));
String content = helper.executeAsString(request);
assertThat(content, is("foobar"));
}
});
代码示例来源:origin: jooby-project/jooby
public Request post(final String path) {
this.req = new Request(this, executor(), org.apache.http.client.fluent.Request.Post(host
+ path));
return req;
}
代码示例来源:origin: dreamhead/moco
@Override
public void run() throws Exception {
Request request = Request.Post(root()).bodyForm(new BasicNameValuePair("name", "dreamhead"));
String content = helper.executeAsString(request);
assertThat(content, is("foobar"));
}
});
代码示例来源:origin: dreamhead/moco
@Override
public void run() throws IOException {
Request request = Request.Post(remoteUrl("/template")).bodyForm(new BasicNameValuePair("name", "dreamhead"));
assertThat(helper.executeAsString(request), is("dreamhead"));
}
});
代码示例来源:origin: dreamhead/moco
@Override
public void run() throws Exception {
org.apache.http.client.fluent.Request request = Post(root()).bodyForm(new BasicNameValuePair("name", "dreamhead"));
assertThat(helper.executeAsString(request), is("foobar"));
}
});
代码示例来源:origin: dreamhead/moco
@Test
public void should_match_form_value() throws IOException {
runWithConfiguration("form.json");
Request request = Request.Post(root()).bodyForm(new BasicNameValuePair("name", "dreamhead"));
assertThat(helper.executeAsString(request), is("foobar"));
}
代码示例来源:origin: dreamhead/moco
@Test
public void should_return_form_value_from_template() throws IOException {
runWithConfiguration("template.json");
Request request = Request.Post(remoteUrl("/form_template")).bodyForm(new BasicNameValuePair("foo", "dreamhead"));
assertThat(helper.executeAsString(request), is("dreamhead"));
}
代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons
@Override
public Request post(String partialUrl) {
String url = baseUrl + partialUrl;
return Request.Post(url);
}
代码示例来源:origin: rancher/cattle
@Override
public void delete(long accountId, String value) throws IOException {
Request.Post(SECRETS_URL.get() + PURGE_PATH).bodyString(value, ContentType.APPLICATION_JSON).execute().handleResponse((response) -> {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode >= 300 && statusCode != 404) {
throw new IOException("Failed to delete secret :" + response.getStatusLine().getReasonPhrase());
}
return IOUtils.toString(response.getEntity().getContent());
});
}
代码示例来源:origin: org.apache.sling/org.apache.sling.distribution.core
public static boolean deletePackage(Executor executor, URI distributionURI, String remotePackageId) throws URISyntaxException, IOException {
URI deleteUri = getDeleteUri(distributionURI, remotePackageId);
Request deleteReq = Request.Post(deleteUri).useExpectContinue();
HttpResponse httpResponse = executor.execute(deleteReq).returnResponse();
return httpResponse.getStatusLine().getStatusCode() == 200;
}
代码示例来源:origin: org.streampipes/streampipes-pipeline-management
public PipelineElementStatus invoke() {
LOG.info("Invoking element: " + belongsTo);
try {
Response httpResp = Request.Post(belongsTo).bodyString(jsonLd(), ContentType.APPLICATION_JSON).connectTimeout(10000).execute();
return handleResponse(httpResp);
} catch (Exception e) {
LOG.error(e.getMessage());
return new PipelineElementStatus(belongsTo, payload.getName(), false, e.getMessage());
}
}
代码示例来源:origin: streampipes/streampipes-ce
private Integer subscribeConsumer(String kafkaRestUrl, String consumerInstance, String kafkaTopic) throws IOException {
String subscribeConsumerUrl = getConsumerInstanceUrl(kafkaRestUrl, consumerInstance, kafkaTopic)
+ "/subscription";
return Request.Post(subscribeConsumerUrl)
.addHeader(HttpHeaders.CONTENT_TYPE, KAFKA_REST_CONTENT_TYPE)
.addHeader(HttpHeaders.ACCEPT, KAFKA_REST_CONTENT_TYPE)
.body(new StringEntity(makeSubscribeConsumerBody(kafkaTopic), Charsets.UTF_8))
.execute()
.returnResponse()
.getStatusLine()
.getStatusCode();
}
代码示例来源:origin: org.streampipes/streampipes-pipeline-management
private EventSchema makeRequest() {
String httpRequestBody = GsonSerializer.getGsonWithIds().toJson(dataProcessorInvocation);
try {
Response httpResp = Request.Post(dataProcessorInvocation.getBelongsTo() + "/output").bodyString(httpRequestBody,
ContentType
.APPLICATION_JSON).execute();
return handleResponse(httpResp);
} catch (Exception e) {
e.printStackTrace();
return new EventSchema();
}
}
代码示例来源:origin: mgtechsoftware/smockin
HttpClientResponseDTO post(final HttpClientCallDTO reqDto) throws IOException {
final Request request = Request.Post(reqDto.getUrl());
handleRequestData(request, reqDto.getHeaders(), reqDto);
return executeRequest(request, reqDto.getHeaders());
}
代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing
@When("^\"([^\"]*)\" asks for a token for attachment \"([^\"]*)\"$")
public void postDownload(String username, String attachmentId) throws Throwable {
String blobId = blobIdByAttachmentId.get(attachmentId);
AccessToken accessToken = userStepdefs.authenticate(username);
response = Request.Post(baseUri(mainStepdefs.jmapServer).setPath("/download/" + blobId).build())
.addHeader("Authorization", accessToken.serialize())
.execute()
.returnResponse();
}
代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing
private static String getContinuationToken(URIBuilder uriBuilder, String username) throws ClientProtocolException, IOException, URISyntaxException {
Response response = Request.Post(uriBuilder.setPath("/authentication").build())
.bodyString("{\"username\": \"" + username + "\", \"clientName\": \"Mozilla Thunderbird\", \"clientVersion\": \"42.0\", \"deviceName\": \"Joe Blogg’s iPhone\"}",
ContentType.APPLICATION_JSON)
.setHeader("Accept", ContentType.APPLICATION_JSON.getMimeType())
.execute();
return JsonPath.parse(response.returnContent().asString())
.read("continuationToken");
}
内容来源于网络,如有侵权,请联系作者删除!