Hi, 

   We are getting a "MalformedChunkException: CRLF expected at end of 
chunk" Exception at the place where is.read is done? Any suggestions?

Thank you,
B.Arunkumar

On Friday, November 16, 2012 3:29:43 PM UTC+5:30, B.Arunkumar wrote:
>
> Hi,
>
>   I am using the DefaultHttpClient to post an xml using HTTPPost and the 
> xml response InputStream write to a file on SD Card as per the code:
>
> HttpConnectionParams.setConnectionTimeout(my_httpParams,30000);
> HttpConnectionParams.setSoTimeout(my_httpParams, 30000);
>
> DefaultHttpClient Client = new DefaultHttpClient(my_httpParams);
>
> String xml = "<?xml version='1.0' encoding='UTF-8'?><CMSearchDescription 
> xmlns='urn:psialliance-org'>.......</CMSearchDescription>";
> StringEntity se = null;
> se = new StringEntity(xml,"UTF-8");
> se.setContentType("application/atom+xml");
>
> HttpPost httpPost = new HttpPost(url);
> String auth = android.util.Base64.encodeToString((Username + ":" + 
> Password).getBytes("UTF-8"), android.util.Base64.NO_WRAP);
> httpPost.addHeader("Authorization", "Basic "+ auth);
>
> httpPost.setEntity(se);
> HttpResponse Response = Client.execute(httpPost);
>
> InputStream is =Response.getEntity().getContent();
>
> File root = Environment.getExternalStorageDirectory();
> String localFilePath = root.getPath() + "/myFile1.xml";
> FileOutputStream fos = new FileOutputStream(localFilePath, false);
> OutputStream os = new BufferedOutputStream(fos);
> byte[] buffer = new byte[1024];
>  
> int byteRead = 0;
>
> while ((byteRead = is.read(buffer)) >0) {
>          os.write(buffer, 0, byteRead);
> }
> fos.close();
>
> However, when the file on the SD Card is opened, the XML file is 
> incomplete as below:
>
>
> <EventId>6534</EventId><startTime>2012-10-31T08:08:07Z</startTime><alarmTime>2012-10-31T08:09:07Z</alarmTime><endTime>2012-10-31T08:10:07Z</endTime></timeSpan><timeSpan><EventId>6532</EventId><startTime>2012-10-31T08:05:12Z</startTime><alarmTime>2012-10-31T08:06:12Z</alarmTime><endTime>2012-10-31T08:07:12Z</endTime></timeSpan><timeSpan><EventId>6529</EventId
>
> The HTTPresponse InputStream itself seems incomplete. Why is this 
> happening and what can be done to avaoid this problem? 
>
> (The XML response is big of the order of 80000 bytes).
>
> Thank you,
> B.Arunkumar
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to