本文整理匯總了Java中org.apache.http.client.methods.HttpRequestBase.getMethod方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpRequestBase.getMethod方法的具體用法?Java HttpRequestBase.getMethod怎麽用?Java HttpRequestBase.getMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.methods.HttpRequestBase
的用法示例。
在下文中一共展示了HttpRequestBase.getMethod方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: performRequest
import org.apache.http.client.methods.HttpRequestBase; //導入方法依賴的package包/類
public CloseableHttpResponse performRequest(HttpRequestBase request, boolean revalidate) {
String method = request.getMethod();
if (revalidate) {
request.addHeader(HttpHeaders.CACHE_CONTROL, "max-age=0");
}
CloseableHttpResponse response;
try {
response = executeGetOrHead(request);
} catch (IOException e) {
throw new HttpRequestException(String.format("Could not %s '%s'.", method, request.getURI()), e);
}
return response;
}
示例2: addRequestBody
import org.apache.http.client.methods.HttpRequestBase; //導入方法依賴的package包/類
private static HttpRequestBase addRequestBody(HttpRequestBase httpRequest, HttpEntity entity) {
if (entity != null) {
if (httpRequest instanceof HttpEntityEnclosingRequestBase) {
((HttpEntityEnclosingRequestBase)httpRequest).setEntity(entity);
} else {
throw new UnsupportedOperationException(httpRequest.getMethod() + " with body is not supported");
}
}
return httpRequest;
}
示例3: getWire
import org.apache.http.client.methods.HttpRequestBase; //導入方法依賴的package包/類
/**
* method to get the wire.
* @param method
* @param responseBody
* @param headerString
* @param responseStatus
* @param subTests
* @return
* @throws ComplianceException
*/
public static Wire getWire(HttpRequestBase method, String responseBody,
String headerString, String responseStatus,
ArrayList<String> subTests) throws ComplianceException {
StringBuffer toServer = new StringBuffer();
StringBuffer fromServer = new StringBuffer();
StringBuffer subTestsPerformed = new StringBuffer();
toServer.append(method.getRequestLine().getMethod()).append(" ");
toServer.append(method.getRequestLine().getUri()+"\n");
toServer.append(method.getRequestLine().getProtocolVersion().getProtocol());
for (org.apache.http.Header header : method.getAllHeaders()) {
toServer.append(header.getName()).append(": ").append(header.getValue()).append("\n");
}
if(method.getMethod() != "GET" && method.getMethod() != "DELETE"){
try {
HttpEntity entity = ((HttpEntityEnclosingRequest)method).getEntity();
toServer.append(EntityUtils.toString(entity));
} catch (Exception e) {
throw new ComplianceException(500, "Error in getting the request payload");
}
}
fromServer.append("\n" + "Headers : ");
fromServer.append(headerString + "\n");
fromServer.append("\n" + "Status : ");
fromServer.append(responseStatus + "\n");
fromServer.append("\n" + responseBody);
for (String subTest : subTests) {
subTestsPerformed.append(subTest).append("\n");
}
return new Wire(toServer.toString(), fromServer.toString(), subTestsPerformed.toString());
}