Android failing to send large json string through Http Post - android

I am trying to send an image as a base64 to a php based web service. The image that I am sending is around 500 kb . I am first compressing the image and then converting the image into base64 string. But the image is not being sent. If i try it through Fiddler, I am successful in sending the image. Is there anyway to increase the http post request call of android? I am using the following libraries: DefaultHttpClient and HttpPost.

In my case , adding UTF-8 solved my problem
StringEntity se;
se = new StringEntity(json.toString(),"UTF-8");
httppostreq.setEntity(se);
response = client.execute(httppostreq);

Related

Decode a string encoded with Brotli returned by Android Volley

I'm sending an http request to a website using Volley (POST and StringRequest). The call is correctly executed. However, I can see that the result is a string codified. When seeing the headers of the answer I can see it is encoded in br, which means brotli. How can I decode the answer to later read it as a JSON?
Should I change to OkHttp or another alternative?

Android Compress data for posting to web server

I am still a beginner in Android. I am currently sending large amount of data(json) from the android app to web server using HTTPClient. I found that HttpURLConnection supports decompression for request but is there any support or any way that I can upload a compress/gzipped json to the web server?
Is the only way to achieve this is to manually gzip the json string and put the gzipped string into in to the post?
You can add GZIP compression in your HTTP header.
HttpUriRequest request = new HttpGet(url);
request.addHeader("Content-Encoding", "gzip");
// ...
httpClient.execute(request);
You can check this link for more information

Sending Image to server in android

In android I am trying to send image to the server.I am using Multipart request. But when I add image in format ByteArray to the Multipart UnsupportedEncodingException occurs.
following is my code.
Do I need to add mime type to request.
If possible please post the complete Sample code.
Try converting the Image to Base64 format string and then sending that string to the server.
Here's the link to convert image to base64 format.
And then at server end decode it.
I done it with the use of MultiPartEntity . Added image as byteArrayBody and done the HTTP request.

Getting Size of Http request and response

I am study about doPost and get method to send data from android app to tomcat server.
I am trying to check the size of http request and response because I am sure that request and response was sending data and catching data from tomcat server.
I used this example ,
http://www.avajava.com/tutorials/lessons/how-do-i-determine-the-content-length-of-a-request.html
to check the contents length.
After I get contents length, i get two questions
First, contents-length represents whole size of http request ?
if it is not, then how can i check the size of http request (by bytes)?
second , I am still having a trouble to getting size of response ?
I tried
How to Get the HTTP Response Size in Java (in Bytes)
Determine size of HTTP Response?
but i was getting error to get size of http response
is there any way to get size of http response ?
thanks
No, it is not the size of the whole request. It is the length of the message body, excluding status line and headers.
Not all servers provide the content length. If you use chunked transfer encoding, the content length cannot be determined without downloading the whole response. If the server sends the "Content-Length" header, you can get the size of the message body. You need to hook the socket stream to get the actual (full) response size.

Sending HTTPPost in Android

I am new to android development. What I am trying to do is send some data on a server. i.e. the HTTPPOst.
For example I want to send an image or send an XML in the HTTP Post's Body....
Can some body give me sample code or project.

Categories

Resources