use of cz.msebera.android.httpclient.HttpResponse in project AndroidStudy by tinggengyan.
the class HttpCookie method run.
@Override
public void run() {
list.add(new BasicNameValuePair("name", "steve"));
list.add(new BasicNameValuePair("age", "12"));
try {
post.setEntity(new UrlEncodedFormEntity(list));
HttpResponse response = client.execute(post);
if (response.getStatusLine().getStatusCode() == 200) {
AbstractHttpClient absclient = (AbstractHttpClient) client;
List<Cookie> cookies = absclient.getCookieStore().getCookies();
for (Cookie cookie : cookies) {
System.out.println("name==" + cookie.getName());
System.out.println("value==" + cookie.getValue());
Message message = new Message();
message.obj = cookie;
mHandler.sendMessage(message);
return;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of cz.msebera.android.httpclient.HttpResponse in project Simple-Dilbert by smarek.
the class GetStripUrl method doInBackground.
@Override
protected String[] doInBackground(Void... params) {
if (this.currDate == null) {
Log.e(TAG, "Cannot load for null date");
return null;
}
String cached = this.preferences.getCachedUrl(this.currDate);
if (cached != null) {
return new String[] { cached, this.preferences.getCachedTitle(this.currDate) };
}
HttpGet get = new HttpGet("http://dilbert.com/strip/" + currDate.toString(DilbertPreferences.DATE_FORMATTER) + "/");
HttpResponse response = null;
CloseableHttpClient client = null;
try {
client = HttpClients.createSystem();
response = client.execute(get);
} catch (Exception e) {
Log.e(TAG, "HttpGet failed", e);
}
if (response == null) {
return null;
}
String[] rtn = handleParse(response);
try {
client.close();
} catch (IOException e) {
Log.e(TAG, "Closing HttpClient failed", e);
}
return rtn;
}
use of cz.msebera.android.httpclient.HttpResponse in project Zom-Android by zom.
the class OtrDataHandler method onIncomingResponse.
public void onIncomingResponse(Address from, Address to, byte[] value) {
// Log.e( TAG, "onIncomingResponse:" + value.length);
SessionInputBuffer buffer = new MemorySessionInputBuffer(value);
HttpResponseParser parser = new HttpResponseParser(buffer, lineParser, responseFactory, params);
HttpResponse res;
try {
res = (HttpResponse) parser.parse();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (HttpException e) {
e.printStackTrace();
return;
}
String uid = res.getFirstHeader("Request-Id").getValue();
Request request = requestCache.get(uid);
if (request == null) {
debug("Unknown request ID " + uid);
return;
}
if (request.isSeen()) {
debug("Already seen request ID " + uid);
return;
}
request.seen();
int statusCode = res.getStatusLine().getStatusCode();
if (statusCode != 200) {
debug("got status " + statusCode + ": " + res.getStatusLine().getReasonPhrase());
// TODO handle error
return;
}
// TODO handle success
try {
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
readIntoByteBuffer(byteBuffer, buffer);
// debug("Received sha1 @" + request.start + " is " + sha1sum(byteBuffer.toByteArray()));
if (request.method.equals("GET")) {
Transfer transfer = transferCache.get(request.url);
if (transfer == null) {
debug("Transfer expired for url " + request.url);
return;
}
transfer.chunkReceived(request, byteBuffer.toByteArray());
if (transfer.isDone()) {
// Log.e( TAG, "onIncomingResponse: isDone");
debug("Transfer complete for " + request.url);
String filename = transfer.closeFile();
Uri vfsUri = SecureMediaStore.vfsUri(filename);
if (transfer.checkSum()) {
// Log.e( TAG, "onIncomingResponse: writing");
if (mDataListener != null)
mDataListener.onTransferComplete(false, null, from.getAddress(), transfer.url, transfer.type, vfsUri.toString());
} else {
if (mDataListener != null)
mDataListener.onTransferFailed(false, null, to.getAddress(), transfer.url, "checksum");
debug("Wrong checksum for file");
}
} else {
if (mDataListener != null)
mDataListener.onTransferProgress(true, null, to.getAddress(), transfer.url, ((float) transfer.chunksReceived) / transfer.chunks);
transfer.perform();
debug("Progress " + transfer.chunksReceived + " / " + transfer.chunks);
}
}
} catch (IOException e) {
debug("Could not read line from response");
} catch (RemoteException e) {
debug("Could not read remote exception");
}
}
use of cz.msebera.android.httpclient.HttpResponse in project android-async-http by loopj.
the class AsyncHttpRequest method makeRequest.
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);
}
Aggregations