diff --git a/modules/juce_core/native/juce_android_Network.cpp b/modules/juce_core/native/juce_android_Network.cpp index 2cb1a96e41..55e33f8b2f 100644 --- a/modules/juce_core/native/juce_android_Network.cpp +++ b/modules/juce_core/native/juce_android_Network.cpp @@ -235,9 +235,9 @@ private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl) }; -URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener) +URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost) { - return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener); + return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost); } //============================================================================== diff --git a/modules/juce_core/native/juce_curl_Network.cpp b/modules/juce_core/native/juce_curl_Network.cpp index 50c192e1c2..9c14f69848 100644 --- a/modules/juce_core/native/juce_curl_Network.cpp +++ b/modules/juce_core/native/juce_curl_Network.cpp @@ -548,7 +548,7 @@ public: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl) }; -URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener) +URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost) { - return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener); + return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost); } diff --git a/modules/juce_core/native/juce_linux_Network.cpp b/modules/juce_core/native/juce_linux_Network.cpp index c8154f96b2..c2965a323e 100644 --- a/modules/juce_core/native/juce_linux_Network.cpp +++ b/modules/juce_core/native/juce_linux_Network.cpp @@ -573,8 +573,8 @@ private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Pimpl) }; -URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener) +URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost) { - return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener); + return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost); } #endif diff --git a/modules/juce_core/native/juce_mac_Network.mm b/modules/juce_core/native/juce_mac_Network.mm index 8f5b8ee66b..6410a8b223 100644 --- a/modules/juce_core/native/juce_mac_Network.mm +++ b/modules/juce_core/native/juce_mac_Network.mm @@ -406,7 +406,8 @@ struct BackgroundDownloadTask : public URL::DownloadTask BackgroundDownloadTask (const URL& urlToUse, const File& targetLocationToUse, String extraHeadersToUse, - URL::DownloadTask::Listener* listenerToUse) + URL::DownloadTask::Listener* listenerToUse, + bool shouldUsePostRequest) : targetLocation (targetLocationToUse), listener (listenerToUse), uniqueIdentifier (String (urlToUse.toString (true).hashCode64()) + String (Random().nextInt64())) { @@ -419,6 +420,9 @@ struct BackgroundDownloadTask : public URL::DownloadTask activeSessions.set (uniqueIdentifier, this); NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:juceStringToNS (urlToUse.toString (true))]]; + if (shouldUsePostRequest) + [request setHTTPMethod: @"POST"]; + StringArray headerLines; headerLines.addLines (extraHeadersToUse); headerLines.removeEmptyStrings (true); @@ -633,9 +637,9 @@ struct BackgroundDownloadTask : public URL::DownloadTask HashMap BackgroundDownloadTask::activeSessions; -URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener) +URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool usePostRequest) { - ScopedPointer downloadTask = new BackgroundDownloadTask (*this, targetLocation, extraHeaders, listener); + ScopedPointer downloadTask = new BackgroundDownloadTask (*this, targetLocation, extraHeaders, listener, usePostRequest); if (downloadTask->initOK() && downloadTask->connect()) return downloadTask.release(); @@ -648,9 +652,9 @@ void URL::DownloadTask::juce_iosURLSessionNotify (const String& identifier) BackgroundDownloadTask::invokeNotify (identifier); } #else -URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener) +URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool usePost) { - return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener); + return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, usePost); } #endif @@ -912,9 +916,9 @@ private: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (URLConnectionState) }; -URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener) +URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost) { - return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener); + return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost); } #pragma clang diagnostic pop diff --git a/modules/juce_core/native/juce_win32_Network.cpp b/modules/juce_core/native/juce_win32_Network.cpp index 3aa2e2a7ae..42f17d9db2 100644 --- a/modules/juce_core/native/juce_win32_Network.cpp +++ b/modules/juce_core/native/juce_win32_Network.cpp @@ -651,7 +651,7 @@ bool JUCE_CALLTYPE Process::openEmailWithAttachments (const String& targetEmailA return mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS; } -URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener) +URL::DownloadTask* URL::downloadToFile (const File& targetLocation, String extraHeaders, DownloadTask::Listener* listener, bool shouldUsePost) { - return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener); + return URL::DownloadTask::createFallbackDownloader (*this, targetLocation, extraHeaders, listener, shouldUsePost); } diff --git a/modules/juce_core/network/juce_URL.cpp b/modules/juce_core/network/juce_URL.cpp index 05ace94262..60c791a3a9 100644 --- a/modules/juce_core/network/juce_URL.cpp +++ b/modules/juce_core/network/juce_URL.cpp @@ -106,14 +106,15 @@ URL::DownloadTask::Listener::~Listener() {} URL::DownloadTask* URL::DownloadTask::createFallbackDownloader (const URL& urlToUse, const File& targetFileToUse, const String& extraHeadersToUse, - Listener* listenerToUse) + Listener* listenerToUse, + bool usePostRequest) { const size_t bufferSize = 0x8000; targetFileToUse.deleteFile(); if (ScopedPointer outputStream = targetFileToUse.createOutputStream (bufferSize)) { - ScopedPointer stream = new WebInputStream (urlToUse, false); + ScopedPointer stream = new WebInputStream (urlToUse, usePostRequest); stream->withExtraHeaders (extraHeadersToUse); if (stream->connect (nullptr)) diff --git a/modules/juce_core/network/juce_URL.h b/modules/juce_core/network/juce_URL.h index 80430bbe15..32f2633b05 100644 --- a/modules/juce_core/network/juce_URL.h +++ b/modules/juce_core/network/juce_URL.h @@ -372,7 +372,7 @@ public: private: friend class URL; - static DownloadTask* createFallbackDownloader (const URL&, const File&, const String&, Listener*); + static DownloadTask* createFallbackDownloader (const URL&, const File&, const String&, Listener*, bool); public: #if JUCE_IOS @@ -395,7 +395,8 @@ public: */ DownloadTask* downloadToFile (const File& targetLocation, String extraHeaders = String(), - DownloadTask::Listener* listener = nullptr); + DownloadTask::Listener* listener = nullptr, + bool usePostCommand = false); //============================================================================== /** Tries to download the entire contents of this URL into a binary data block.