本文整理汇总了Java中cz.msebera.android.httpclient.HttpResponse类的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse类的具体用法?Java HttpResponse怎么用?Java HttpResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpResponse类属于cz.msebera.android.httpclient包,在下文中一共展示了HttpResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendResponseMessage
import cz.msebera.android.httpclient.HttpResponse; //导入依赖的package包/类
@Override
public void sendResponseMessage(HttpResponse response) throws IOException {
// do not process if request has been cancelled
if (!Thread.currentThread().isInterrupted()) {
StatusLine status = response.getStatusLine();
byte[] responseBody;
responseBody = getResponseData(response.getEntity());
// additional cancellation check as getResponseData() can take non-zero time to process
if (!Thread.currentThread().isInterrupted()) {
if (status.getStatusCode() >= 300) {
sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), responseBody, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()));
} else {
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody);
}
}
}
}
示例2: isRedirectRequested
import cz.msebera.android.httpclient.HttpResponse; //导入依赖的package包/类
@Override
public boolean isRedirectRequested(
final HttpResponse response,
final HttpContext context) {
if (!enableRedirects) {
return false;
}
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
int statusCode = response.getStatusLine().getStatusCode();
switch (statusCode) {
case HttpStatus.SC_MOVED_TEMPORARILY:
case HttpStatus.SC_MOVED_PERMANENTLY:
case HttpStatus.SC_SEE_OTHER:
case HttpStatus.SC_TEMPORARY_REDIRECT:
return true;
default:
return false;
} //end of switch
}
示例3: sendResponseMessage
import cz.msebera.android.httpclient.HttpResponse; //导入依赖的package包/类
@Override
public void sendResponseMessage(HttpResponse response) throws IOException {
if (!Thread.currentThread().isInterrupted()) {
StatusLine status = response.getStatusLine();
if (status.getStatusCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) {
//already finished
if (!Thread.currentThread().isInterrupted())
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), null);
} else if (status.getStatusCode() >= 300) {
if (!Thread.currentThread().isInterrupted())
sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()));
} else {
if (!Thread.currentThread().isInterrupted()) {
Header header = response.getFirstHeader(AsyncHttpClient.HEADER_CONTENT_RANGE);
if (header == null) {
append = false;
current = 0;
} else {
AsyncHttpClient.log.v(LOG_TAG, AsyncHttpClient.HEADER_CONTENT_RANGE + ": " + header.getValue());
}
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), getResponseData(response.getEntity()));
}
}
}
}
示例4: get
import cz.msebera.android.httpclient.HttpResponse; //导入依赖的package包/类
public static Hostplace get(String ip) throws Exception {
HttpGet httppost = new HttpGet(Geocode.url + "/" + ip);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject json = new JSONObject(data);
if (json.getString("status").equals("fail"))
throw new Exception();
Hostplace hostplace = Hostplace.getJson(json);
return hostplace;
}
throw new Exception();
}
示例5: getBlock
import cz.msebera.android.httpclient.HttpResponse; //导入依赖的package包/类
public static Block getBlock(String blockhash) throws Exception {
HttpGet httppost = new HttpGet(Insight.url + "/block/" + blockhash);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject json = new JSONObject(data);
Block block = Block.getJson(json);
return block;
}
throw new Exception();
}
示例6: getBlockHash
import cz.msebera.android.httpclient.HttpResponse; //导入依赖的package包/类
public static String getBlockHash(String height) throws Exception {
HttpGet httppost = new HttpGet(Insight.url + "/block-index/" + height);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject json = new JSONObject(data);
String hash = json.getString("blockHash");
return hash;
}
throw new Exception();
}
示例7: getTx
import cz.msebera.android.httpclient.HttpResponse; //导入依赖的package包/类
public static Tx getTx(String hash) throws Exception {
HttpGet httppost = new HttpGet(Insight.url + "/tx/" + hash);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject json = new JSONObject(data);
Tx tx = Tx.getJson(json);
return tx;
}
throw new Exception();
}
示例8: makeRequest
import cz.msebera.android.httpclient.HttpResponse; //导入依赖的package包/类
private void makeRequest() throws IOException {
if (isCancelled()) {
return;
}
// Fixes #115
if (request.getURI().getScheme() == null) {
// subclass of IOException so processed in the caller
throw new MalformedURLException("No valid URI scheme was provided");
}
if (responseHandler instanceof RangeFileAsyncHttpResponseHandler) {
((RangeFileAsyncHttpResponseHandler) responseHandler).updateRequestHeaders(request);
}
HttpResponse response = client.execute(request, context);
if (isCancelled()) {
return;
}
// Carry out pre-processing for this response.
responseHandler.onPreProcessResponse(responseHandler, response);
if (isCancelled()) {
return;
}
// The response is ready, handle it.
responseHandler.sendResponseMessage(response);
if (isCancelled()) {
return;
}
// Carry out post-processing for this response.
responseHandler.onPostProcessResponse(responseHandler, response);
}
示例9: execute
import cz.msebera.android.httpclient.HttpResponse; //导入依赖的package包/类
private JSONObject execute(HttpPost request, JSONObject payload) throws IOException, NetworkException, JSONException {
setPayloadXsrf(payload);
request.setEntity(new ByteArrayEntity(payload.toString().getBytes()));
authenticateRequest(request);
HttpResponse resp = client.execute(request, httpContext);
StatusLine sl = resp.getStatusLine();
if (sl.getStatusCode() != 200) throw new NetworkException(sl);
return new JSONObject(EntityUtils.toString(resp.getEntity(), Charset.forName("UTF-8")));
}
示例10: getHtmlConsolePage
import cz.msebera.android.httpclient.HttpResponse; //导入依赖的package包/类
private static String getHtmlConsolePage(String dev_acc, CookieStore cookieStore) throws IOException, NetworkException {
HttpGet get = new HttpGet(Utils.DEVELOPER_CONSOLE_URL + "?dev_acc=" + dev_acc);
HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
HttpResponse resp = client.execute(get);
StatusLine sl = resp.getStatusLine();
if (sl.getStatusCode() != 200) throw new NetworkException(sl);
return EntityUtils.toString(resp.getEntity(), Charset.forName("UTF-8"));
}
示例11: doInBackground
import cz.msebera.android.httpclient.HttpResponse; //导入依赖的package包/类
@Override
protected Void doInBackground(String... message) {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.instruman.it/assets/feedback/update.php");
try {
//add data
List<NameValuePair> nameValuePairs = new ArrayList<>(1);
nameValuePairs.add(new BasicNameValuePair("stars", message[0]));
nameValuePairs.add(new BasicNameValuePair("message", message[1]));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//execute http post
HttpResponse response = httpclient.execute(httppost);
} catch (Exception e) {
}
return null;
}
示例12: getHttpDocument
import cz.msebera.android.httpclient.HttpResponse; //导入依赖的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());
}
示例13: deletePost
import cz.msebera.android.httpclient.HttpResponse; //导入依赖的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);
}
}
示例14: handleParse
import cz.msebera.android.httpclient.HttpResponse; //导入依赖的package包/类
private String handleParse(HttpResponse response) {
String foundUrl = FindUrls.extractUrls(response);
if (null != foundUrl) {
preferences
.saveCurrentUrl(currDate
.toString(DilbertPreferences.DATE_FORMATTER), foundUrl);
}
return foundUrl;
}
示例15: extractUrls
import cz.msebera.android.httpclient.HttpResponse; //导入依赖的package包/类
public static String extractUrls(HttpResponse response) {
String found = null;
try {
Scanner scan;
Header contentEncoding = response
.getFirstHeader("Content-Encoding");
if (contentEncoding != null
&& contentEncoding.getValue().equalsIgnoreCase("gzip")) {
scan = new Scanner(new GZIPInputStream(response.getEntity()
.getContent()));
} else {
scan = new Scanner(response.getEntity().getContent());
}
found = scan.findWithinHorizon(url_match_pattern, 0);
if (null != found) {
Matcher m = url_match_pattern.matcher(found);
if (m.matches())
found = m.group(1);
}
scan.close();
EntityUtils.consume(response.getEntity());
} catch (Throwable t) {
Log.e(LOG_TAG, "Error Occurred", t);
}
return found;
}