# HTTP POST Request Issue

**URL:** <https://discourse.processing.org/t/http-post-request-issue/4338>\
**Category:** Processing for Pi\
**Created:** [October 10, 2018, 5:06pm UTC](https://discourse.processing.org/t/http-post-request-issue/4338 "2018-10-10T17:06:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![samcox89](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@samcox89](https://discourse.processing.org/u/samcox89)\
**Post date:** [October 10, 2018, 5:06pm UTC](https://discourse.processing.org/t/http-post-request-issue/4338/1 "2018-10-10T17:06:10Z")

</div>

Hi there,

At a basic level, i’ve got a Raspberry Pi with MusicBox loaded. I’m using a second machine to change the audio using HTTP requests.

My request is - { “method”: “core.playback.get\_current\_tl\_track”, “jsonrpc”: “2.0”, “id”: 1 } posted with the header “Content-Type”, “application/json”);"

If I use another peice of software, for example Postman, to send the string, it works.

I’m using the HTTP Request library from Dan Shiftman. The issue, i think, is when I use post.addData it requires two strings, a key and a value. I just want to send the raw string.

Any advice?

Thanks,

Sam

---

<div class="post-metadata">

**Author:** ![gohai](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gohai/32/25_2.png) [@gohai](https://discourse.processing.org/u/gohai)\
**Post date:** [October 11, 2018, 2:37am UTC](https://discourse.processing.org/t/http-post-request-issue/4338/2 "2018-10-11T02:37:40Z")

</div>

Can you post your code?

---

<div class="post-metadata">

**Author:** ![samcox89](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@samcox89](https://discourse.processing.org/u/samcox89)\
**Post date:** [October 11, 2018, 8:39am UTC](https://discourse.processing.org/t/http-post-request-issue/4338/3 "2018-10-11T08:39:44Z")

</div>

sure! When I print out, the string is formatted correctly, as in:

{“method”: core.playback.get\_current\_tl\_track,“jsonrpc”: 2.0,“id”: 1 }

```auto
import http.requests.*;
String test = "{\"method\": core.playback.get_current_tl_track,\"jsonrpc\": 2.0,\"id\": 1 }";
public void setup() 
{
  size(400, 400);
  smooth();

  PostRequest post = new PostRequest("http://172.16.3.139:6680/mopidy/rpc");
  post.addHeader("Content-Type", "application/json");

  //curl -d '{ "method": "core.playback.get_current_tl_track", "jsonrpc": "2.0", "id": 1 }' http://172.16.3.139:6680/mopidy/rpc
  post.addData("json", test); // NOTE --- its here that's confusing me. I simply want to send the string, post.addData states that it requires two values (presumably a key and a value)??

  println(test);

  post.send();
  System.out.println("Reponse Content: " + post.getContent());
  System.out.println("Reponse Content-Length Header: " + post.getHeader("Content-Length"));
}

```

---

<div class="post-metadata">

**Author:** ![samcox89](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@samcox89](https://discourse.processing.org/u/samcox89)\
**Post date:** [October 12, 2018, 9:13am UTC](https://discourse.processing.org/t/http-post-request-issue/4338/4 "2018-10-12T09:13:50Z")

</div>

SOLVED - I dived into the library and found addJson that accepts one single value. Inside the library i changed the header to “httpPost.addHeader(“content-type”, “application/json”);”

This fixed the issue
