一直在這一天工作,並沒有得到它的地方。試圖獲取Java中的Google Spreadsheet返回HTTP錯誤405
我的Java代碼如下所示:
final URL url = new URL(String.format("https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=%s&exportFormat=tsv&gid=0", spreadsheetId));
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", "GoogleLogin auth=" + wiseAuth.getAuthToken());
conn.setRequestProperty("GData-Version", "3.0");
conn.setRequestMethod("GET");
conn.setDoOutput(true); // trouble here, see below
conn.setInstanceFollowRedirects(true);
conn.connect();
試圖做conn.getInputStream()
時,我總是得到一個FileNotFound錯誤。我將其縮小到響應代碼是405方法不允許。例外是返回我的網址,我可以在我的瀏覽器中正常訪問該頁面。我發現setDoOutput(true)
在內部執行POST。但是,如果我刪除該行,conn.getInputStream()
爲空,並且conn.getOutputStream()
似乎不會返回任何內容 - 但也許我將其設置爲錯誤?
除了我不相信API讓我導出/檢索文件作爲TSV,這是我的最終目標。 – GJTorikian
然後查看此示例:http://code.google.com/apis/documents/docs/3.0/developers_guide_java.html#DownloadingSpreadsheets。它允許您導出爲TSV文件。 – limc