[英]Ruby - open-uri doesn't download a file itself, but just the HTML code of the website
我正在嘗試使用以下代碼段:
open("data.csv", "wb") do |file|
file << open("https://website.com/data.php", http_basic_authentication: ["username", "password"]).read
end
但是,我沒有下載所需的CSV文件,而是下載了該網站的HTML代碼。 有什么問題? 當我訪問URL且未登錄時,它會顯示登錄表單(不是HTTP身份驗證窗口)。 如何解決這種情況?
謝謝
我認為您應該嘗試net / http http://dzone.com/snippets/how-download-files-ruby
這可能是因為您的php腳本返回的響應類型為text / plain或更佳的mime類型:text / csv
請參閱此相關的先前回復
在PHP腳本中:
header('Content-Type: text/csv');
header('Content-disposition: attachment;filename=data.csv');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.