I make a soap request in my Android app using HttpURLConnection the response is a base64 encoded string holding the data of an image.
the problem is that the response always received in complete. so the image can not be constructed correctly.
what can be the reason for this ?
thanks
A friend of mine blogged about this a year or so ago. Base64 is supposed to be built in, but isn't/wasn't? He has details here.
Possibly server is sending the incorrect Content-Length header.
Did you write the server code?
Happened to me once when I was reporting the content length based on the size of buffer not the actual size of data inside buffer.
Related
I send a request off to our server and receive a response from the server. The response contains information related to an image. The server returns the image as a base64 string. It is taking way to long (30-40 seconds per image) to parse out the data so I can pull the information I need to save and view the image. I am looking for suggestions on better ways that might help to speed up the process. I am currently using a SAX parser and the slow down is when the .parse function is called.
I want to upload or post a image file on server using REST WCF. For this I am using JSON as input format.
But when I am checking this post call with debugger due to Base64 image data input is not accepted by the debugger .
I was giving me the 400-Bad Request response for this call.
Thanks.
First understand the concept of JSON/REST.
Then Make your WCF method to input the Byte[] i.e. Byte Array.
Convert your Image in Base64 and Pass it to the REST.
In order to send Image to JSON Web Service, you need to convert that to Byte Array or Base 64 String Representation.
Hope this helps.
I am using this question's source code How to asynchronous perform a httprequest and show the progress of downloading the response in order to fetch a webpage's html source and display a progressbar with the downloaded data so far and how much the total size of the page is.
That particular code doesn't actually work on ICS 4.0.3 because clHeaders[0] doesn't point to anything and an exception is raised called ArrayIndexOutOfBounds at index 0 because the Content-Length header is omitted from the server's response. I tried using getContentLength in case that was the problem - it returned a negative value of -1 then I iterated over all the headers and the Content-Length was not there. After removing those bits, the code works fine and a webpage is fetched, written to a file and the size as it is being downloaded is displayed but obviously not the end size till I actually download it all.
I only have three ideas of the cause:
I am not sending a Content-Length header thus I am not receiving one either - but this sounds wrong. Plus I have no idea if the HttpClient isn't sending one in the background.
I read here in another question that if the response of the server was streaming or chunked then getContentLength can return -1.
Gzip? But I have no idea how to disable it or if it was enabled in the first place
If you are thinking it's the server that is broken, I tried many websites including Google and still no Content-Length header whatsoever.
Content-Length header is optional, it's mostly only useful for HEAD request or for very large data where the client might decide they want to abort the request if the content is too large. So yes, Content-Length dies not always exist. Other than that, you should generally just get the content length by reading the data.
There are cases where the Content-Length should not be included in the response or should be ignored. These cases are documented on the W3 site. If your content has a transfer encoding of gzip for example, the content-length should be ignored.
I'm trying to send an image as a Base64 encoded string to my PHP script via HttpGet, but as I kind of expected I get a 414 URI too large from my server.
Is there a way to post large strings with HttpGet?
Any help is greatly appreciated.
URI limit depends on server settings and its not a good idea to send huge data via Get method. And no, you cant use Post on Get service.
The best would be to alter your webservice to receive Post request and then you may send as long data as you want
when the URI is too large (cause of you are using it to send an image...) all you can do is to try to make it smaller, by compressing it. Or if you have access to the server, increase the limit....
the one way or the other.... use http-post instead of http-get.
you wont have the problem that the size is limited (or if theres a limit, its way bigger then the one from http-get) and i cant believe that sending an image via http-get is usage as intended by the http
I am sending a POST request to a web-service which returns data in XML format. When I invoke the web-service via the browser i can see the complete XML file. However, when I call the web-service from my android app (in emulator) I only get partial XML data?
The size of the XML file being sent is approx 14500 bytes. I first store the response in a byte array whose size i calculate using getContentLength() function. This method returns the correct size of the response.
However, my InputStreamReader reads approximately 6350 bytes of the actual data to the byte array. The remaining part of the byte array simply contains zeros.
I tried looking everywhere online but so far I haven't come across a solution. Yes chunking is one option but since I dont have access to the web-service code I can't implement that option.
Really appreciate if someone could guide me here!
I don't understand why do you need to use InputStreamReader (which can behave very wrong if you are not careful) to read web service data (in your case it is only around 14.5kb). Just use HttpURLConnection, connect to your ws, and it will take care for you about the connection and also the response connection.getResponseMessage();