android - Add header to (HTTP request for) file download -



android - Add header to (HTTP request for) file download -

working example, utilize next code download file:

url = new url(sturl); connection = (httpurlconnection) url.openconnection(); connection.addrequestproperty ("foo", "bar"); connection.setdooutput(true); // update per comment! connection.connect(); // download file = new bufferedinputstream( url.openstream(), 8192 ); os = new bufferedoutputstream( new fileoutputstream( tmp ) ); copystream( is, os );

this works fine downloading. including foo/barheader in http request fails.

why?

updates:

download url = "http://x0data.com/android/default/rqst" i want pass headers (not or post parameters) i know server ok, because used work (for android code seem have lost...)

ok, great help @greenapps. next seems include headers while downloading file:

url = new url(sturl); connection = (httpurlconnection) url.openconnection(); connection.addrequestproperty ("foo", "bar"); connection.setdooutput(true); outputstreamwriter author = new outputstreamwriter(connection.getoutputstream()); writer.flush(); string line; bufferedreader reader = new bufferedreader(new inputstreamreader(connection.getinputstream()));

now, need figure how write bufferedreader file...

(and test & verify...)

android android-4.3-jelly-bean

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -