Search code examples
androidhttp-posthigh-traffic

how much of data usage a http post request?


I am writing an application for android and in the app i use some HttpPost requests. i have a service in which i schedule 3 request at constant times. one every 1.5 seconds, one every 7 seconds and one every 20 seconds. most of times web service don't return any thing.

i install my app on a device and check it for 2 days. this app use 40M data although viber use only 4M . (i found it by check data usage part at device settings.)

how much data use by a simple HttpPost request?

how i can reduce data usage in my app ?


Solution

  • Well, the only person able to find out how much any POST request costs is you. It depends a lot on the headers/data you send.

    HTTP introduces some overhead in the data sent. For example, using cURL to post just a pair of values p1=v1 and p2=v2, those are the headers sent:

    POST / HTTP/1.1
    User-Agent: curl/7.35.0
    Host: localhost
    Accept: */*
    Content-Length: 11
    Content-Type: application/x-www-form-urlencoded
    

    Those are just the headers (the body adds 11 bytes to this). As you can guess, doing this every 1.5 seconds creates a lot of traffic.

    To reduce this, you can do some things:

    • Lower the rate of requests to the server. Do you really need to post every 1,5 seconds?
    • If you post a lot of data, check if HttpPost lets you compress the data you send / the server supports HTTP compression;
    • Consider the usage of other technologies like plain sockets/websockets. If the data you post is small this will help by reducing the overhead of HTTP.

    EDIT: I am assuming you are using POST requests to really post data to the server. If you are using it to get some kind of state from the server, something like (Web)sockets or using push notifications can reduce a lot the requests required.