本文整理了Java中org.apache.http.client.fluent.Request.bodyString
方法的一些代码示例,展示了Request.bodyString
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.bodyString
方法的具体详情如下:
包路径:org.apache.http.client.fluent.Request
类名称:Request
方法名:bodyString
暂无
代码示例来源:origin: jooby-project/jooby
public Request body(final String body, final String type) {
if (type == null) {
byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
HttpEntity entity = new InputStreamEntity(new ByteArrayInputStream(bytes), bytes.length);
req.body(entity);
} else {
req.bodyString(body, ContentType.parse(type));
}
return this;
}
代码示例来源: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 patchForResponse(final String url, final String content) throws IOException {
return executeAsString(Request.Patch(url)
.bodyString(content, ContentType.DEFAULT_TEXT));
}
代码示例来源:origin: dreamhead/moco
@Override
public void run() throws IOException {
assertThat(helper.get(remoteUrl("/proxy")), is("get_proxy"));
assertThat(helper.postContent(remoteUrl("/proxy"), "proxy"), is("post_proxy"));
Request putRequest = Request.Put(remoteUrl("/proxy")).bodyString("proxy", ContentType.DEFAULT_TEXT);
assertThat(helper.executeAsString(putRequest), is("put_proxy"));
Request deleteRequest = Request.Delete(remoteUrl("/proxy"));
assertThat(helper.executeAsString(deleteRequest), is("delete_proxy"));
Request headRequest = Request.Head(remoteUrl("/proxy"));
StatusLine headStatusLine = helper.execute(headRequest).getStatusLine();
assertThat(headStatusLine.getStatusCode(), is(200));
Request optionsRequest = Request.Options(remoteUrl("/proxy"));
assertThat(helper.executeAsString(optionsRequest), is("options_proxy"));
Request traceRequest = Request.Trace(remoteUrl("/proxy"));
assertThat(helper.executeAsString(traceRequest), is("trace_proxy"));
}
});
代码示例来源:origin: org.apache.httpcomponents/fluent-hc
public Request bodyForm(final Iterable <? extends NameValuePair> formParams, final Charset charset) {
final List<NameValuePair> paramList = new ArrayList<NameValuePair>();
for (final NameValuePair param : formParams) {
paramList.add(param);
}
final ContentType contentType = ContentType.create(URLEncodedUtils.CONTENT_TYPE, charset);
final String s = URLEncodedUtils.format(paramList, charset);
return bodyString(s, contentType);
}
代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.apache.httpcomponents.httpclient
public Request bodyForm(final Iterable <? extends NameValuePair> formParams, final Charset charset) {
final List<NameValuePair> paramList = new ArrayList<NameValuePair>();
for (NameValuePair param : formParams) {
paramList.add(param);
}
final ContentType contentType = ContentType.create(URLEncodedUtils.CONTENT_TYPE, charset);
final String s = URLEncodedUtils.format(paramList, charset != null ? charset.name() : null);
return bodyString(s, contentType);
}
代码示例来源: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: Kurento/kurento-java
@Override
public void connect() throws IOException {
try {
org.apache.http.client.fluent.Request.Post(url).bodyString("", ContentType.APPLICATION_JSON)
.execute();
} catch (ClientProtocolException e) {
// Silence http connection exception. This indicate that server is
// reachable and running
}
}
代码示例来源:origin: mesosphere/dcos-commons
/**
* Create a new secret.
*
* @param path location to create the secret
* @param secret a secret definition
* @throws IOException if the create operation failed to complete
*/
public void create(String path, Payload secret) throws IOException {
Request httpRequest = Request.Put(uriForPath(path))
.bodyString(OBJECT_MAPPER.writeValueAsString(secret), ContentType.APPLICATION_JSON);
query("create", path, httpRequest, HttpStatus.SC_CREATED);
}
代码示例来源:origin: mesosphere/dcos-commons
/**
* Update a secret.
*
* @param path path which contains an existing secret
* @param secret an updated secret definition
* @throws IOException if the update failed to complete
*/
public void update(String path, Payload secret) throws IOException {
Request httpRequest = Request.Patch(uriForPath(path))
.bodyString(OBJECT_MAPPER.writeValueAsString(secret), ContentType.APPLICATION_JSON);
query("update", path, httpRequest, HttpStatus.SC_NO_CONTENT);
}
代码示例来源: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
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: 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: com.github.dcshock/consul-rest-client
/**
* Issue a PUT to the given URL with a JSON body.
*/
public static HttpResp put(final String url, final String body) throws IOException {
return Http.toHttpResp(executor.execute(Request.Put(url)
.bodyString(body, ContentType.APPLICATION_JSON))
.returnResponse()
);
}
代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing
private static Response postAuthenticate(URIBuilder uriBuilder, String password, String continuationToken) throws ClientProtocolException, IOException, URISyntaxException {
return Request.Post(uriBuilder.setPath("/authentication").build())
.bodyString("{\"token\": \"" + continuationToken + "\", \"method\": \"password\", \"password\": \"" + password + "\"}",
ContentType.APPLICATION_JSON)
.setHeader("Accept", ContentType.APPLICATION_JSON.getMimeType())
.execute();
}
代码示例来源:origin: adridadou/eth-contract-api
public SwarmHash publish(final String content) {
try {
Response response = Request.Post(host + "/bzzr:/")
.bodyString(content, ContentType.TEXT_PLAIN)
.execute();
return SwarmHash.of(response.returnContent().asString());
} catch (IOException e) {
throw new EthereumApiException("error while publishing the smart contract metadata to Swarm", e);
}
}
代码示例来源:origin: edu.jhuapl.dorset/dorset-core
private Response put(HttpRequest request) throws IOException {
Request apacheRequest = Request.Put(request.getUrl());
if (request.getBody() != null) {
ContentType ct = ContentType.create(request.getContentType().getMimeType(),
request.getContentType().getCharset());
apacheRequest.bodyString(request.getBody(), ct);
} else if (request.getBodyForm() != null) {
apacheRequest.bodyForm(buildFormBody(request.getBodyForm()));
}
prepareRequest(apacheRequest);
return apacheRequest.execute();
}
代码示例来源:origin: edu.jhuapl.dorset/dorset-core
private Response post(HttpRequest request) throws IOException {
Request apacheRequest = Request.Post(request.getUrl());
if (request.getBody() != null) {
ContentType ct = ContentType.create(request.getContentType().getMimeType(),
request.getContentType().getCharset());
apacheRequest.bodyString(request.getBody(), ct);
} else if (request.getBodyForm() != null) {
apacheRequest.bodyForm(buildFormBody(request.getBodyForm()));
}
prepareRequest(apacheRequest);
return apacheRequest.execute();
}
代码示例来源: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");
}
代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing
public void post(String requestBody) throws Exception {
response = Request.Post(baseUri(mainStepdefs.jmapServer).setPath("/jmap").build())
.addHeader("Authorization", userStepdefs.authenticate(userStepdefs.getConnectedUser()).serialize())
.addHeader("Accept", org.apache.http.entity.ContentType.APPLICATION_JSON.getMimeType())
.bodyString(requestBody, org.apache.http.entity.ContentType.APPLICATION_JSON)
.execute()
.returnResponse();
jsonPath = JsonPath.using(Configuration.defaultConfiguration()
.addOptions(Option.SUPPRESS_EXCEPTIONS))
.parse(response.getEntity().getContent());
}
}
内容来源于网络,如有侵权,请联系作者删除!