本文整理汇总了Java中cz.msebera.android.httpclient.client.methods.HttpUriRequest类的典型用法代码示例。如果您正苦于以下问题:Java HttpUriRequest类的具体用法?Java HttpUriRequest怎么用?Java HttpUriRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpUriRequest类属于cz.msebera.android.httpclient.client.methods包,在下文中一共展示了HttpUriRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendRequest
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
protected RequestHandle sendRequest(DefaultHttpClient client,
HttpContext httpContext, HttpUriRequest uriRequest,
String contentType, ResponseHandlerInterface responseHandler,
Context context) {
if (contentType != null) {
uriRequest.addHeader(AsyncHttpClient.HEADER_CONTENT_TYPE, contentType);
}
responseHandler.setUseSynchronousMode(true);
/*
* will execute the request directly
*/
newAsyncHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context).run();
// Return a Request Handle that cannot be used to cancel the request
// because it is already complete by the time this returns
return new RequestHandle(null);
}
示例2: getWikiResponse
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
/**
* Gets a standard {@link WikiResponse} object for a wiki request. Because
* I was getting sick of all that boilerplate.
*
* @param httpclient an active HTTP session
* @param httpreq an HTTP request (GET or POST)
* @return a WikiResponse containing WikiResponsey stuff
*/
@NonNull
private static WikiResponse getWikiResponse(@NonNull CloseableHttpClient httpclient,
@NonNull HttpUriRequest httpreq) throws Exception {
WikiResponse toReturn = new WikiResponse();
toReturn.document = getHttpDocument(httpclient, httpreq);
toReturn.rootElem = toReturn.document.getDocumentElement();
if(doesResponseHaveError(toReturn.rootElem)) {
toReturn.hasError = true;
toReturn.errorTextId = getErrorTextId(findErrorCode(toReturn.rootElem));
throw new WikiException(toReturn.errorTextId);
}
return toReturn;
}
示例3: process
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
public void process(HttpResponse httpResponse, HttpContext httpContext) throws HttpException, IOException {
if (httpResponse.getStatusLine().getStatusCode() == 302) {
final URI reqUri = ((HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST)).getURI();
final HttpHost currentHost = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
final String url = (reqUri.isAbsolute()) ? reqUri.toString() : (currentHost.toURI() + reqUri.getPath());
final String redirect = httpResponse.getLastHeader("Location").getValue();
String strDate = "";
if(url.equals(Fetcher.ROOT)) {
strDate = CommonUtils.splitDate(pattern,redirect);
newIssueNum = CommonUtils.dateStrToLong("yyyy-MM-dd",strDate);
}
Log.d(SectionFragment.class.getName(),"interceptor" + redirect + ":::" + strDate + " "+ (newIssueNum >AppContext.getLatestIssueNum()));
Log.d(SectionFragment.class.getName(),"interceptor: " + url);
}
}
示例4: process
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
public void process(HttpResponse httpResponse, HttpContext httpContext) throws HttpException, IOException {
if (httpResponse.getStatusLine().getStatusCode() == 302) {
final URI reqUri = ((HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST)).getURI();
final HttpHost currentHost = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
final String url = (reqUri.isAbsolute()) ? reqUri.toString() : (currentHost.toURI() + reqUri.getPath());
final String redirect = httpResponse.getLastHeader("Location").getValue();
String pattern = "([0-9]{4}-[0-9]{2}-[0-9]{2})";
String strDate="";
if(url.equals(Fetcher.ROOT)) {
strDate = CommonUtils.splitDate(pattern,redirect);
newIssueNum = CommonUtils.dateStrToLong("yyyy-MM-dd",strDate);
}
Log.d("interceptor",redirect + ":::" + strDate + " "+ newIssueNum);
Log.d("interceptor",url);
}
}
示例5: newAsyncHttpRequest
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
protected AsyncHttpRequest newAsyncHttpRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
AsyncHttpRequest httpRequest = getHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context);
return httpRequest == null
? super.newAsyncHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context)
: httpRequest;
}
示例6: retryRequest
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
boolean retry = true;
Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
boolean sent = (b != null && b);
if (executionCount > maxRetries) {
// Do not retry if over max retry count
retry = false;
} else if (isInList(exceptionWhitelist, exception)) {
// immediately retry if error is whitelisted
retry = true;
} else if (isInList(exceptionBlacklist, exception)) {
// immediately cancel retry if the error is blacklisted
retry = false;
} else if (!sent) {
// for most other errors, retry only if request hasn't been fully sent yet
retry = true;
}
if (retry) {
// resend all idempotent requests
HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
if (currentReq == null) {
return false;
}
}
if (retry) {
SystemClock.sleep(retrySleepTimeMS);
} else {
exception.printStackTrace();
}
return retry;
}
示例7: updateRequestHeaders
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
public void updateRequestHeaders(HttpUriRequest uriRequest) {
if (file.exists() && file.canWrite())
current = file.length();
if (current > 0) {
append = true;
uriRequest.setHeader("Range", "bytes=" + current + "-");
}
}
示例8: getHttpDocument
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
/**
* Returns the content of a http request as an XML Document. This is to be
* used only when we know the response to a request will be XML. Otherwise,
* this will probably throw an exception.
*
* @param httpclient an active HTTP session
* @param httpreq an HTTP request (GET or POST)
* @return a Document containing the contents of the response
*/
private static Document getHttpDocument(@NonNull CloseableHttpClient httpclient,
@NonNull HttpUriRequest httpreq) throws Exception {
// Remember the last request. We might want to abort it later.
mLastRequest = httpreq;
HttpResponse response = httpclient.execute(httpreq);
HttpEntity entity = response.getEntity();
return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(entity.getContent());
}
示例9: deletePost
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception {
String url = getUsingUrl(true) + "v1/posts/" + model.postNumber;
HttpEntity entity = ExtendedMultipartBuilder.create().setDelegates(listener, task).addString("password", model.password).build();
HttpUriRequest request = null;
HttpResponse response = null;
HttpEntity responseEntity = null;
try {
request = RequestBuilder.delete().setUri(url).setEntity(entity).build();
response = httpClient.execute(request);
StatusLine status = response.getStatusLine();
switch (status.getStatusCode()) {
case 200:
return null;
case 400:
responseEntity = response.getEntity();
InputStream stream = IOUtils.modifyInputStream(responseEntity.getContent(), null, task);
JSONObject json = new JSONObject(new JSONTokener(new BufferedReader(new InputStreamReader(stream))));
throw new Exception(json.getString("message"));
default:
throw new Exception(status.getStatusCode() + " - " + status.getReasonPhrase());
}
} finally {
try { if (request != null) request.abort(); } catch (Exception e) {}
EntityUtils.consumeQuietly(responseEntity);
if (response != null && response instanceof Closeable) IOUtils.closeQuietly((Closeable) response);
}
}
示例10: ScribeRequestAdapter
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
public ScribeRequestAdapter(
cz.msebera.android.httpclient.client.methods.HttpUriRequest httpUriRequest) {
super(getMethod(httpUriRequest.getMethod()), httpUriRequest.getURI().toString());
this.httpUriRequest = httpUriRequest;
this.oauthParameters = new HashMap<String, String>();
}
示例11: getHttpRequest
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
public AsyncHttpRequest getHttpRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
return null;
}
示例12: getHttpRequest
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
public AsyncHttpRequest getHttpRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
return new PrePostProcessRequest(client, httpContext, uriRequest, responseHandler);
}
示例13: PrePostProcessRequest
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
public PrePostProcessRequest(AbstractHttpClient client, HttpContext httpContext, HttpUriRequest request, ResponseHandlerInterface responseHandler) {
super(client, httpContext, request, responseHandler);
}
示例14: sendRequest
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
/**
* Puts a new request in queue as a new thread in pool to be executed
*
* @param client HttpClient to be used for request, can differ in single requests
* @param contentType MIME body type, for POST and PUT requests, may be null
* @param context Context of Android application, to hold the reference of request
* @param httpContext HttpContext in which the request will be executed
* @param responseHandler ResponseHandler or its subclass to put the response into
* @param uriRequest instance of HttpUriRequest, which means it must be of HttpDelete,
* HttpPost, HttpGet, HttpPut, etc.
* @return RequestHandle of future request process
*/
protected RequestHandle sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
if (uriRequest == null) {
throw new IllegalArgumentException("HttpUriRequest must not be null");
}
if (responseHandler == null) {
throw new IllegalArgumentException("ResponseHandler must not be null");
}
if (responseHandler.getUseSynchronousMode() && !responseHandler.getUsePoolThread()) {
throw new IllegalArgumentException("Synchronous ResponseHandler used in AsyncHttpClient. You should create your response handler in a looper thread or use SyncHttpClient instead.");
}
if (contentType != null) {
if (uriRequest instanceof HttpEntityEnclosingRequestBase && ((HttpEntityEnclosingRequestBase) uriRequest).getEntity() != null && uriRequest.containsHeader(HEADER_CONTENT_TYPE)) {
log.w(LOG_TAG, "Passed contentType will be ignored because HttpEntity sets content type");
} else {
uriRequest.setHeader(HEADER_CONTENT_TYPE, contentType);
}
}
responseHandler.setRequestHeaders(uriRequest.getAllHeaders());
responseHandler.setRequestURI(uriRequest.getURI());
AsyncHttpRequest request = newAsyncHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context);
threadPool.submit(request);
RequestHandle requestHandle = new RequestHandle(request);
if (context != null) {
List<RequestHandle> requestList;
// Add request to request map
synchronized (requestMap) {
requestList = requestMap.get(context);
if (requestList == null) {
requestList = Collections.synchronizedList(new LinkedList<RequestHandle>());
requestMap.put(context, requestList);
}
}
requestList.add(requestHandle);
Iterator<RequestHandle> iterator = requestList.iterator();
while (iterator.hasNext()) {
if (iterator.next().shouldBeGarbageCollected()) {
iterator.remove();
}
}
}
return requestHandle;
}
示例15: AsyncHttpRequest
import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
public AsyncHttpRequest(AbstractHttpClient client, HttpContext context, HttpUriRequest request, ResponseHandlerInterface responseHandler) {
this.client = Utils.notNull(client, "client");
this.context = Utils.notNull(context, "context");
this.request = Utils.notNull(request, "request");
this.responseHandler = Utils.notNull(responseHandler, "responseHandler");
}