HttpGet problem with Chunked encoding

by m5p3nc3r » Thu, 05 Mar 2009 11:46:33 GMT


Sponsored Links
 Hi Guys

I am having issues retrieving the contents of a chunk encoded web
page. all pages that I try to retrieve throw:
  org.apache.http.MalformedChunkCodingException: Chunked stream ended
unexpectedly

If I retrieve a page with no chunk encoding, the code works fine.


HttpClient httpClient=new DefaultHttpClient();
HttpGet httpGet=new HttpGet(url);
ResponseHandler<String> rh=new BasicResponseHandler();
String response=httpClient.execute(httpGet,rh);

This will work with www.nds.com (no chunk encoding)
but fail with www.google.co.uk (chunk encoding)

Now, I am assuming this is a problem with the apache httpclient
library, but wanted to know if anyone else has seen this problem and
if there is a way of working around it in the current release.

I am using android-sdk-linux_x86-1.1_r1

Regards

Matt

--~--~---------~--~----~------------~-------~--~----~



HttpGet problem with Chunked encoding

by m5p3nc3r » Sat, 07 Mar 2009 01:48:01 GMT


 Sorry for replying to my own post, but it seems that this is a problem
with the version of httpclient/httpcore that is installed with r1.1 of
the SDK.

If I download the latest verison: Core 4.0 and Client 4.0-Beta2,
everything works fine on my Linux desktop.  There is a line in the
release note of Core 4.0:

* [HTTPCORE-175] Chunk decoders no longer accept truncated chunks as
valid input.
  Contributed by Oleg Kalnichevski <olegk at apache.org>

That makes me think this has been fixed in that version.

So my question to the group are:
1, How do I tell what version of libraries are installed on the
system?
2, Is it possible for me to upgrade libraries on the system?  If so,
how?
3, If I have to wait for the libraries to be upgraded, is there a
release schedule I can track anywhere?

Cheers

Matt



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


HttpGet problem with Chunked encoding

by Mark Murphy » Sat, 07 Mar 2009 02:10:00 GMT


 


Not easily.

The source code for Apache HttpClient is integrated into the overall
Android git repo system:

 http://android.git.kernel.org/?p=platform/external/apache-http.git ;a=summary

They just imported the source code, without any sort of RELEASE file.
The quick peek I took at some of the commit log entries does not
indicate which version they have.

On the other hand, since the source is there, you can probably track
major changes by looking for classes introduced in a release. So, if
HttpClient 4.0 added some class, and HttpClient-in-Android is missing
said class, then HttpClient-in-Android isn't on 4.0.

Anybody know a good way to discern which HttpClient is in git?


It is conceivable, though unlikely, that an in-APK edition of HttpClient
would supercede the system libraries.

If you are willing to build your own firmware, you can try replacing
HttpClient, but you might have to make changes to any other code that
uses the older version, if there are API differences, etc.


That I can't help you on...

Please file your problem, and the suggestion of the HttpClient 4.0
upgrade, in  http://b.android.com , if you haven't already.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 

Android Training on the Ranch! -- Mar 16-20, 2009
 http://www.bignerdranch.com/schedule.shtml 

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. How to get the real width of pixels of a string?

Well I have to admit I almost adore this problem description. You can
try Paint.measureText()
http://developer.android.com/reference/android/graphics/Paint.html





-- 

2. AudioRecord on Samsung Moment

When switching between the emulator (which supports 8KHz) and a real
phone like the G1 (which supports 16KHz), I used the following code to
set up a valid AudioRecord object:

AudioRecord ar;

// Try to construct at 16KHz
ar = new AudioRecord(
  MediaRecorder.AudioSource.MIC,
  16000,
  AudioFormat.CHANNEL_CONFIGURATION_MONO,
  AudioFormat.ENCODING_PCM_16BIT,
  AUDIO_BUFFER_SIZE);

if (ar.getState() != AudioRecord.STATE_INITIALIZED) {
  // Unable to set up at 16KHz, try at 8KHz
  ar = new AudioRecord(
    MediaRecorder.AudioSource.MIC,
    8000,
    AudioFormat.CHANNEL_CONFIGURATION_MONO,
    AudioFormat.ENCODING_PCM_16BIT,
    AUDIO_BUFFER_SIZE);
}

This seems to work just fine, and a 16KHz AudioRecord object is
instantiated on the G1, and a 8KHz object is instantiated on the
emulator.

However, on the Samsung Moment, which only supports 8KHz,
AudioRecord.getState() returns STATE_INITIALIZED when trying to
construct with 16KHz.  This ends up causing recording to fail since
it's trying to record at 16KHz, even though the phone doesn't support
it.  Also, I don't see any exceptions thrown when I try to wrap the
construction in a try-catch.

Does anyone know of a better way to detect 16KHz vs. 8KHz capabilities
on the device?

3. How to get the real width of pixels of a string?

4. How to open new view (call an activity) from options menu defined in XML

5. Strange crashing while using OpenGL

6. Forward locking or copy protection outside the Marketplace

7. HTC S740 Android Porting