URL createInputStream with post data, wrongly put get parameters in the post body

I’m trying to send a binary blob to some influxdb endpoint with the JUCE URL class. I noticed that when you have post data while using createInputStream, JUCE will end up removing the get parameters from the endpoint, and append them to the body, breaking both the endpoint to reach and the payload:

// osx code in WebInputStream::Pimpl::createConnection
if (NSURL* nsURL = [NSURL URLWithString: juceStringToNS (url.toString (! isPost))])

// win code in WebInputStream::Pimpl::connect
String address = url.toString (! isPost);

// linux code in WebInputStream::Pimpl::setOptions
auto address = url.toString (! isPost);

// android in WebInputStream::Pimpl::connect
String address = url.toString (! isPost);

then createHeadersAndPostData will append the get parameters in the body, so the receiver is getting something different from what i’m expecting:

void URL::createHeadersAndPostData (String& headers, MemoryBlock& postDataToWrite) const
{
    // ...

    else
    {
        data << URLHelpers::getMangledParameters (*this)        // < this is making my data wrong
             << postData;

i’ve opened a PR to fix it (https://github.com/juce-framework/JUCE/pull/707), and also improved URL::createInputStream to take an std::function instead of a function pointer and a void* context.

2 Likes

Bump, this is quite annoying that juce put get parameters in the post body and i need to patch or merge juce everytime i pull or switch upstream. Any chance to speed this up?

Bump from me as well, I’m experiencing this same bug ('PUT' file with URL output stream) and I’d love for it to get fixed! :pray: