Android DownloadManager with POST method?
Asked Answered
J

1

7


I started to work with android.app.DownloadManager and faced a problem.
By default, DM sending HTTP GET request to download file:

GET http://www.example.com/getfile HTTP/1.1
Cookie: id=sdfsdf;Max-Age=10800000;Path=/
Host: ___
Connection: Keep-Alive
User-Agent: AndroidDownloadManager Paros/3.2.13
Content-length: 0

But I need to send some data in request(e.g. json string)
Are there any ways to send HTTP POST request in DownloadManager

Juratory answered 26/6, 2012 at 17:50 Comment(2)
if your data is not too important, you can add your data in the get request (while encoding special chars) like this : example.com/getfile?id=xxx&data=%e9l%e9ment%20encod%e9Convexity
Thanks, I knew that, but the requirement is to send data in the body of request.Juratory
C
3

While waiting for another more accurate answer :

I don't think you can add data to this request since, as you said it, it's a GET request and not POST.

Maybe this thread can give you a hint on another way to achieve what you want if the Download-Manager is not absolutely required : How do download a file with login using HttpURLConnection

Convexity answered 4/7, 2012 at 14:26 Comment(1)
I'am actually dropped this method, and made downloading with AsyncTask. But it's still very wierd, that developers didn't made that simple option to the DM, which, I guess, very commonly used.Juratory

© 2022 - 2024 — McMap. All rights reserved.