function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
justin_sfdcjustin_sfdc 

Webservice POST response

Hi everyone,

I am currently performing the POST callout to an external system upon which it sends me binary Excel file. When I add the condition in my VFpage to download the file as Excel, the file gets downloaded, but its in binary format and not readable. 

Is there any way we can convert it to UTF-8.

Below is the code of the response the Handler is sending back?
var HandlerResponse = (HttpWebResponse)request.GetResponse();
            MemoryStream mStream = new MemoryStream();
            HandlerResponse.GetResponseStream().CopyTo(mStream);

            byte[] bArray = mStream.ToArray();

            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = HandlerResponse.ContentType;

            string strDisposition = HandlerResponse.GetResponseHeader("Content-Disposition");
            Response.AddHeader("Content-Disposition", strDisposition);

            Response.BinaryWrite(bArray);
            Response.Flush();
            Response.Close();

I believe i should be adding the ContentType for the response too so that it can handle the response. Please suggest me of the ideas of how this can be achieved or if it can be?


Thanks, 
Justin~sfdc
PrasanntaPrasannta (Salesforce Developers) 
Hi,

Please refer to the link below to convert the excel into UTF-8.
http://www.csvimproved.com/csvi-documentation/tutorials/916-save-a-csv-file-as-utf-8

Hope this information helps.