Download file with specific content type

Noor

Do to download a file and set its content type using Java, using python I do it this way:

import urllib2
req = urllib2.Request('http://www.example.com/', data="abc", headers={'Content-type': 'text/plain'})
r = urllib2.urlopen(req)

My questions are:

  1. What's this Python code equivalence for Java ?

  2. Also, is it possible to make an asynchronous download with a callback when the download is completed ?

Thrasd

I am unable to make a comment, so it has to go here. Have you tried any of the many suggestions from how-to-download-and-save-a-file-from-internet-using-java

Update: ok, so you should be able to use a HttpURlConnection

URL url = new URL("http://www.example.com/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// Set Headers
conn.setRequestProperty("Content-Type", "text/plain");

and then you can use conn.getInputStream() to read the response

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to create a file with content and download it with THYMELEAF

From Java

Do I need Content-Type: application/octet-stream for file download?

From Dev

Download an image by changing content type in JSP

From Dev

Force nginx to send specific Content-Type

From Dev

How to download a content as a pdf file in android?

From Dev

How to download a file via a Chrome Content Script?

From Dev

How to download file without specific content type

From Dev

Download a file to a specific folder with python

From Dev

Download file direct to specific location using javascript

From Dev

Change content-type in S3 bucket policy for a specific file extension

From Dev

how to Download Azure PublishSetting file for a specific subscription

From Dev

Download a file with ServiceStack HttpResult: how to specify a file name for downloaded content?

From Dev

How to download file with default name and type in Python

From Dev

How to create a file with content and download it with THYMELEAF

From Dev

Download html textarea content as a file

From Dev

Associate a File Type with a Specific Program

From Dev

Feincms find page with specific content type

From Dev

Content negotiation for File Download In Web API

From Dev

How to download a content as a pdf file in android?

From Dev

How to find a file with specific content?

From Dev

Run script on specific file type

From Dev

How to download a xml file with content from inputtextarea?

From Dev

php ftp download files with specific file extension

From Dev

Is there a way to download parts of the content of a zip file?

From Dev

Detect file type based on content

From Dev

How to get a specific content type response

From Dev

How to assign structure to file content in download widget

From Dev

Download file from webserver and read content on android

From Dev

Download json file content jQuery node js

Related Related

  1. 1

    How to create a file with content and download it with THYMELEAF

  2. 2

    Do I need Content-Type: application/octet-stream for file download?

  3. 3

    Download an image by changing content type in JSP

  4. 4

    Force nginx to send specific Content-Type

  5. 5

    How to download a content as a pdf file in android?

  6. 6

    How to download a file via a Chrome Content Script?

  7. 7

    How to download file without specific content type

  8. 8

    Download a file to a specific folder with python

  9. 9

    Download file direct to specific location using javascript

  10. 10

    Change content-type in S3 bucket policy for a specific file extension

  11. 11

    how to Download Azure PublishSetting file for a specific subscription

  12. 12

    Download a file with ServiceStack HttpResult: how to specify a file name for downloaded content?

  13. 13

    How to download file with default name and type in Python

  14. 14

    How to create a file with content and download it with THYMELEAF

  15. 15

    Download html textarea content as a file

  16. 16

    Associate a File Type with a Specific Program

  17. 17

    Feincms find page with specific content type

  18. 18

    Content negotiation for File Download In Web API

  19. 19

    How to download a content as a pdf file in android?

  20. 20

    How to find a file with specific content?

  21. 21

    Run script on specific file type

  22. 22

    How to download a xml file with content from inputtextarea?

  23. 23

    php ftp download files with specific file extension

  24. 24

    Is there a way to download parts of the content of a zip file?

  25. 25

    Detect file type based on content

  26. 26

    How to get a specific content type response

  27. 27

    How to assign structure to file content in download widget

  28. 28

    Download file from webserver and read content on android

  29. 29

    Download json file content jQuery node js

HotTag

Archive