本文整理了Java中org.eclipse.jetty.client.HttpClient.POST()
方法的一些代码示例,展示了HttpClient.POST()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.POST()
方法的具体详情如下:
包路径:org.eclipse.jetty.client.HttpClient
类名称:HttpClient
方法名:POST
[英]Creates a POST request to the specified URI.
[中]创建对指定URI的POST请求。
代码示例来源:origin: org.eclipse.jetty/jetty-client
/**
* Creates a POST request to the specified URI.
*
* @param uri the URI to POST to
* @return the POST request
* @see #POST(URI)
*/
public Request POST(String uri)
{
return POST(URI.create(uri));
}
代码示例来源:origin: com.ovea.tajin.server/tajin-server-jetty9
/**
* Creates a POST request to the specified URI.
*
* @param uri the URI to POST to
* @return the POST request
* @see #POST(URI)
*/
public Request POST(String uri)
{
return POST(URI.create(uri));
}
代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9
/**
* Creates a POST request to the specified URI.
*
* @param uri the URI to POST to
* @return the POST request
* @see #POST(URI)
*/
public Request POST(String uri)
{
return POST(URI.create(uri));
}
代码示例来源:origin: org.eclipse.jetty/jetty-client
/**
* Performs a POST request to the specified URI with the given form parameters.
*
* @param uri the URI to POST
* @param fields the fields composing the form name/value pairs
* @return the {@link ContentResponse} for the request
* @throws InterruptedException if send threading has been interrupted
* @throws ExecutionException the execution failed
* @throws TimeoutException the send timed out
*/
public ContentResponse FORM(URI uri, Fields fields) throws InterruptedException, ExecutionException, TimeoutException
{
return POST(uri).content(new FormContentProvider(fields)).send();
}
代码示例来源:origin: NationalSecurityAgency/lemongrenade
Request req;
if(graphId != null && graphId.length() > 0) { //ensure this is a 'real' graphId
req = client.POST(restUrl + "graph/" + graphId + "?create=true");
req = client.POST(restUrl + "graph/");
代码示例来源:origin: stackoverflow.com
/*配置sslcontextfactory处理https请求*/
SslContextFactory sslContextFactory = new SslContextFactory();
HttpClient httpClient = new HttpClient(sslContextFactory);
httpClient.setFollowRedirects(false);
httpClient.start();
/*配置post请求的url、body、以及请求头*/
Request request = httpClient.POST("https://a1.easemob.com/yinshenxia/yinshenxia/users");
request.header(HttpHeader.CONTENT_TYPE, "application/json");
request.content(new StringContentProvider("{\"username\":\"jliu\",\"password\":\"123456\"}","utf-8"));
// request.param("username", "jliu");
// request.param("password", "123456");
ContentResponse response = request.send();
String res = new String(response.getContent());
System.out.println(res);
httpClient.stop();
代码示例来源:origin: forcedotcom/EMP-Connector
client.start();
URL endpoint = new URL(loginEndpoint, getSoapUri());
Request post = client.POST(endpoint.toURI());
post.content(new ByteBufferContentProvider("text/xml", ByteBuffer.wrap(soapXmlForLogin(username, password))));
post.header("SOAPAction", "''");
代码示例来源:origin: NationalSecurityAgency/lemongrenade
/**
* @param graphId String for graph ID
* @param graph LemonGraphObject
* @return LemonGraphResponse
* @throws InvalidGraphException thrown when failing to connect and hit graph/
*/
public static LemonGraphResponse postToGraph(String graphId, LemonGraphObject graph) throws InvalidGraphException {
LemonGraphResponse lgr = new LemonGraphResponse();
ContentResponse res = null;
try {
openConnection();
String url = restUrl + "graph/" + graphId;
Request req = client.POST(url);
JSONObject graphContent = graph.get();
req.content(new StringContentProvider(graphContent.toString()), "application/json");
res = req.send();
lgr.parseContentResponse(res); // TODO: check responseCode to be 204?
}
catch (Exception e) {
log.error("Error trying to postToGraph "+e.getMessage());
lgr.setSuccess(false);
}
return lgr;
}
代码示例来源:origin: jpos/jPOS-EE
Request request = http.POST(host).content(new BytesContentProvider(list.toArray(new byte[0][0])));
FutureResponseListener listener = new FutureResponseListener(request);
代码示例来源:origin: de-luxe/burstcoin-jminer
ContentResponse response = httpClient.POST(CoreProperties.getSoloServer() + "/burst")
.param("requestType", "submitNonce")
.param("secretPhrase", CoreProperties.getPassPhrase())
代码示例来源:origin: org.infinispan/infinispan-server-rest
@Test
public void shouldPutEntryWithDefaultTllAndIdleTime() throws Exception {
//when
ContentResponse response = client
.POST(String.format("http://localhost:%d/rest/%s/%s", restServer().getPort(), "expiration", "test"))
.content(new StringContentProvider("test"))
.send();
InternalCacheEntry<String, byte[]> cacheEntry = getCacheEntry("expiration", "test".getBytes());
Metadata metadata = cacheEntry.getMetadata();
//then
ResponseAssertion.assertThat(response).isOk();
Assertions.assertThat(metadata.lifespan()).isEqualTo(DEFAULT_LIFESPAN);
Assertions.assertThat(metadata.maxIdle()).isEqualTo(DEFAULT_MAX_IDLE);
}
代码示例来源:origin: org.infinispan/infinispan-server-rest
@Test
public void shouldPutUnknownFormatValueInCache() throws Exception {
//when
ContentResponse response = client
.POST(String.format("http://localhost:%d/rest/%s/%s", restServer().getPort(), "unknown", "test"))
.content(new StringContentProvider("Hey!"))
.header("Content-type", "application/unknown")
.send();
InternalCacheEntry<String, byte[]> cacheEntry = getCacheEntry("unknown", "test".getBytes());
//then
ResponseAssertion.assertThat(response).isOk();
ResponseAssertion.assertThat(response).hasEtag();
Assertions.assertThat(new String(cacheEntry.getValue())).isEqualTo("Hey!");
}
代码示例来源:origin: org.infinispan/infinispan-server-rest
@Test
public void shouldPutImmortalEntryWithZeroTtlAndIdleTime() throws Exception {
//when
ContentResponse response = client
.POST(String.format("http://localhost:%d/rest/%s/%s", restServer().getPort(), "expiration", "test"))
.content(new StringContentProvider("test"))
.header("timeToLiveSeconds", "0")
.header("maxIdleTimeSeconds", "0")
.send();
InternalCacheEntry<String, byte[]> cacheEntry = getCacheEntry("expiration", "test".getBytes());
Metadata metadata = cacheEntry.getMetadata();
//then
ResponseAssertion.assertThat(response).isOk();
Assertions.assertThat(metadata.lifespan()).isEqualTo(DEFAULT_LIFESPAN);
Assertions.assertThat(metadata.maxIdle()).isEqualTo(DEFAULT_MAX_IDLE);
}
代码示例来源:origin: org.infinispan/infinispan-server-rest
@Test
public void shouldPutEntryWithTtlAndIdleTime() throws Exception {
//when
ContentResponse response = client
.POST(String.format("http://localhost:%d/rest/%s/%s", restServer().getPort(), "expiration", "test"))
.content(new StringContentProvider("test"))
.header("timeToLiveSeconds", "50")
.header("maxIdleTimeSeconds", "50")
.send();
InternalCacheEntry<String, byte[]> cacheEntry = getCacheEntry("expiration", "test".getBytes());
Metadata metadata = cacheEntry.getMetadata();
//then
ResponseAssertion.assertThat(response).isOk();
Assertions.assertThat(metadata.lifespan()).isEqualTo(50 * 1000);
Assertions.assertThat(metadata.maxIdle()).isEqualTo(50 * 1000);
}
代码示例来源:origin: org.infinispan/infinispan-server-rest
@Test
public void shouldPutTextValueInCache() throws Exception {
//when
ContentResponse response = client
.POST(String.format("http://localhost:%d/rest/%s/%s", restServer().getPort(), "default", "test"))
.content(new StringContentProvider("Hey!"))
.header("Content-type", "text/plain;charset=UTF-8")
.send();
InternalCacheEntry<String, byte[]> cacheEntry = getCacheEntry("default", "test".getBytes());
//then
ResponseAssertion.assertThat(response).isOk();
ResponseAssertion.assertThat(response).hasEtag();
Assertions.assertThat(new String(cacheEntry.getValue())).isEqualTo("Hey!");
}
代码示例来源:origin: org.infinispan/infinispan-server-rest
public void performPuts(int numberOfInserts) throws Exception {
for (int i = 0; i < numberOfInserts; ++i) {
String randomKey = UUID.randomUUID().toString();
executorCompletionService.submit(() -> {
if (http2) {
FullHttpRequest putValueInCacheRequest = new DefaultFullHttpRequest(HTTP_1_1, POST, "/rest/default/" + randomKey,
wrappedBuffer("test".getBytes(CharsetUtil.UTF_8)));
nettyHttpClient.sendRequest(putValueInCacheRequest);
return 1;
} else {
try {
String scheme = usesTLS ? "https" : "http";
http1Client
.POST(String.format("%s://localhost:%d/rest/%s/%s", scheme, port, "default", "randomKey"))
.content(new StringContentProvider("test"))
.send();
return 1;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
for (int i = 0; i < numberOfInserts; ++i) {
executorCompletionService.take().get();
}
if (http2) {
nettyHttpClient.getResponses();
}
}
代码示例来源:origin: org.infinispan/infinispan-server-rest
@Test
public void shouldPutImmortalEntryWithMinusOneTtlAndIdleTime() throws Exception {
//when
ContentResponse response = client
.POST(String.format("http://localhost:%d/rest/%s/%s", restServer().getPort(), "expiration", "test"))
.content(new StringContentProvider("test"))
.header("timeToLiveSeconds", "-1")
.header("maxIdleTimeSeconds", "-1")
.send();
InternalCacheEntry<String, byte[]> cacheEntry = getCacheEntry("expiration", "test".getBytes());
Metadata metadata = cacheEntry.getMetadata();
//then
ResponseAssertion.assertThat(response).isOk();
Assertions.assertThat(metadata.lifespan()).isEqualTo(-1);
Assertions.assertThat(metadata.maxIdle()).isEqualTo(-1);
}
代码示例来源:origin: org.infinispan/infinispan-server-rest
@Test
public void shouldConflictWhenTryingToReplaceExistingEntryUsingPost() throws Exception {
//given
putStringValueInCache("default", "test", "test");
//when
ContentResponse response = client
.POST(String.format("http://localhost:%d/rest/%s/%s", restServer().getPort(), "default", "test"))
.content(new StringContentProvider("Hey!"))
.header("Content-type", "text/plain;charset=UTF-8")
.send();
//then
ResponseAssertion.assertThat(response).isConflicted();
}
代码示例来源:origin: org.infinispan/infinispan-server-rest
@Test
public void shouldPutSerializedValueInCache() throws Exception {
//when
TestClass testClass = new TestClass();
testClass.setName("test");
ContentResponse response = client
.POST(String.format("http://localhost:%d/rest/%s/%s", restServer().getPort(), "serialized", "test"))
.content(new BytesContentProvider(convertToBytes(testClass)))
.header("Content-type", "application/x-java-serialized-object")
.send();
InternalCacheEntry<String, byte[]> cacheEntry = getCacheEntry("serialized", "test".getBytes());
TestClass valueFromCache = convertFromBytes(cacheEntry.getValue(), TestClass.class);
//then
ResponseAssertion.assertThat(response).isOk();
ResponseAssertion.assertThat(response).hasEtag();
Assertions.assertThat(valueFromCache.getName()).isEqualTo("test");
}
代码示例来源:origin: org.eclipse.jetty.tests/test-sessions-common
Request request1 = client.POST("http://localhost:" + port1 + contextPath + servletMapping + "?action=set&value=" + value);
ContentResponse response1 = request1.send();
assertEquals(HttpServletResponse.SC_OK,response1.getStatus());
内容来源于网络,如有侵权,请联系作者删除!