Android HttpPut and weird character apparition

111 views Asked by At

I try to send an xml using HttpPut and I always have error 400, I tried with several REST client for firefox and both my URI and XML are ok.

So I check the packet with wireshark and something weird happens, it seems that I have the character '?' at the begining of the xml. Of course this '?' is not in my xml file and I can't find where it comes from. When I put my xml in a variable in the code everything works fine but if I read the xml from the file in the eclipse's assets directory the '?' appears...

Here's a sample of my code, I tried everything: with addHeaders, without add headers, read bytes instead of lines....and got error 400 every time. The problem is from that part of the code cause if I add the first line of the xml file "manually" (as I did in the code I put here) the '?' comes after the first line instead of at the beginning (if I read all the xml from the file)

BufferedReader reader = new BufferedReader(new InputStreamReader(c.getAssets().open("data.xml")));   
String line;
String f="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>";
while((line=reader.readLine()) != null){
    f+=line;    
}
reader.close();
StringEntity se = new StringEntity(new String(f));
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"text/xml;charset=UTF-8"));
            reqPut.setEntity(se);
httpResp =  (BasicHttpResponse) httpCli.execute(reqPut);

So if anyone has a clue about this....

0

There are 0 answers