# \[SOLVED\] Using juce::URL to send POST with body

**URL:** <https://forum.juce.com/t/solved-using-juce-url-to-send-post-with-body/59701>\
**Category:** General JUCE discussion\
**Created:** [January 26, 2024, 1:05pm UTC](https://forum.juce.com/t/solved-using-juce-url-to-send-post-with-body/59701 "2024-01-26T13:05:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheWaveWarden](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thewavewarden/32/13708_2.png) [@TheWaveWarden](https://forum.juce.com/u/TheWaveWarden)\
**Post date:** [January 26, 2024, 1:05pm UTC](https://forum.juce.com/t/solved-using-juce-url-to-send-post-with-body/59701/1 "2024-01-26T13:05:04Z")

</div>

Hi, I’m trying to send data in an HTTP POST, where the data is not stored in parameters but in the body (form-data). A simple Postman request which works looks like this:

![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/8/d/8d802bc6622253110f23358bb4870ab937a638b6.png)

Or as a curl command:

```auto
curl --location 'http://myServer.com/do_something' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'instrument=piano'

```

I’ve tried to replicate this with the `juce::URL` class without success so far:

```auto
	juce::URL url = juce::URL ("http://myserver.com/do_something");

	juce::DynamicObject* dyn_obj = new juce::DynamicObject;
	dyn_obj->setProperty ("instrument", "piano");
	url = url.withPOSTData (JSON::toString (juce::var (dyn_obj)));

	// using juce URL parameters feature doesn't work either:
	// url = url.withParameter ("instrument", "piano");

	auto options = juce::URL::InputStreamOptions (juce::URL::ParameterHandling::inPostData)
	                   .withExtraHeaders ({"Content-Type: application/x-www-form-urlencoded"})
	                   .withConnectionTimeoutMs (10000)
	                   .withResponseHeaders (&response_headers)
	                   .withStatusCode (&status_code)
	                   .withNumRedirectsToFollow (5)
	                   .withHttpRequestCmd ("POST");

	std::unique_ptr<InputStream> stream (url.createInputStream (options));

```

Now upon firing this, the server returns that the body field `instrument` is missing. My best guess is that the post data I appended to the request is not in fact stored in the body, but in the parameters.

Is there a way to tell the URL class to embed the information correctly?

---

<div class="post-metadata">

**Author:** ![TheWaveWarden](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thewavewarden/32/13708_2.png) [@TheWaveWarden](https://forum.juce.com/u/TheWaveWarden)\
**Post date:** [January 27, 2024, 4:49pm UTC](https://forum.juce.com/t/solved-using-juce-url-to-send-post-with-body/59701/2 "2024-01-27T16:49:11Z")

</div>

I found a solution. To anyone wondering in the future, the problem was that the line

```auto
url = url.withPOSTData (JSON::toString (juce::var (dyn_obj)));

```

Would generate the data in json form like so:

```auto
{
  "instrument": "piano"
}

```

However, what was needed in this case apparently is simply

```auto
url = url.withPOSTData ("instrument=piano");

```

---

<div class="post-metadata">

**Author:** ![udisoft](https://avatars.discourse-cdn.com/v4/letter/u/ecccb3/32.png) [@udisoft](https://forum.juce.com/u/udisoft)\
**Post date:** [September 8, 2025, 6:12am UTC](https://forum.juce.com/t/solved-using-juce-url-to-send-post-with-body/59701/3 "2025-09-08T06:12:30Z")

</div>

Thank you for sharing your solution.

I tried this out in JUCE Version 8.0.9 for multiple parameters. The following approach also worked for me.

`juce::String jsonPayload = R"({“instrument”: “Piano”, “note”: 38, “preset”: “classic”})";`  
`url = url.withPOSTData(jsonPayload);`
