使用Java下载文件并设置其内容类型,使用python我这样做:
import urllib2
req = urllib2.Request('http://www.example.com/', data="abc", headers={'Content-type': 'text/plain'})
r = urllib2.urlopen(req)
我的问题是:
Java 的 Python 代码等效性是什么?
另外,是否可以在下载完成后通过回调进行异步下载?
我无法发表评论,所以它必须在这里。您是否尝试过how-to-download-and-save-a-file-from-internet-using-java中的许多建议?
更新:好的,所以你应该能够使用 HttpURlConnection
URL url = new URL("http://www.example.com/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// Set Headers
conn.setRequestProperty("Content-Type", "text/plain");
然后你可以用它conn.getInputStream()
来读取响应
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句