本文整理匯總了Java中org.apache.http.client.fluent.Request.execute方法的典型用法代碼示例。如果您正苦於以下問題:Java Request.execute方法的具體用法?Java Request.execute怎麽用?Java Request.execute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.fluent.Request
的用法示例。
在下文中一共展示了Request.execute方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendRequestToOrion
import org.apache.http.client.fluent.Request; //導入方法依賴的package包/類
/**
* Sends a request to Orion
*
* @param ctxElement
* The context element
* @param path
* the path from the context broker that determines which "operation"will be executed
* @param responseClazz
* The class expected for the response
* @return The object representing the JSON answer from Orion
* @throws OrionConnectorException
* if a communication exception happens, either when contacting the context broker at
* the given address, or obtaining the answer from it.
*/
private <E, T> T sendRequestToOrion(E ctxElement, String path, Class<T> responseClazz) {
String jsonEntity = gson.toJson(ctxElement);
log.debug("Send request to Orion: {}", jsonEntity);
Request req = Request.Post(this.orionAddr.toString() + path)
.addHeader("Accept", APPLICATION_JSON.getMimeType())
.bodyString(jsonEntity, APPLICATION_JSON).connectTimeout(5000).socketTimeout(5000);
Response response;
try {
response = req.execute();
} catch (IOException e) {
throw new OrionConnectorException("Could not execute HTTP request", e);
}
HttpResponse httpResponse = checkResponse(response);
T ctxResp = getOrionObjFromResponse(httpResponse, responseClazz);
log.debug("Sent to Orion. Obtained response: {}", httpResponse);
return ctxResp;
}
示例2: post
import org.apache.http.client.fluent.Request; //導入方法依賴的package包/類
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();
}
示例3: getPage
import org.apache.http.client.fluent.Request; //導入方法依賴的package包/類
static String getPage(String targetURL) throws Exception {
Request x = Request.Get(targetURL);
Response y = x.execute();
Content z = y.returnContent();
return z.toString();
}
示例4: put
import org.apache.http.client.fluent.Request; //導入方法依賴的package包/類
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();
}
示例5: get
import org.apache.http.client.fluent.Request; //導入方法依賴的package包/類
private Response get(HttpRequest request) throws IOException {
Request apacheRequest = Request.Get(request.getUrl());
prepareRequest(apacheRequest);
return apacheRequest.execute();
}
示例6: delete
import org.apache.http.client.fluent.Request; //導入方法依賴的package包/類
private Response delete(HttpRequest request) throws IOException {
Request apacheRequest = Request.Delete(request.getUrl());
prepareRequest(apacheRequest);
return apacheRequest.execute();
}