POST data

Below is a response from an echo server for POST requests, sending it a POST request.

  1. shouldnt the POST body be in the “Data” item ?
  2. Anything unusual about the way the Roku sends POST data?
  3. The Roku is adding the Content-Length:0 header (not in my code), is that affecting the servers ability to read the POST body?
    thanks
{
  "form": {},
  "headers": {
    "Content-Length": "0",
    "Accept-Encoding": "deflate, gzip",
    "Accept": "*/*",
    "Connection": "close",
    "Content-Type": "application/x-www-form-urlencoded",
    "User-Agent": "Roku/DVP-5.1 (025.01E01195A)",
    "Host": "httpbin.org"
  },
  "data": "",
  "url": "http://httpbin.org/post",
  "origin": "XX.XXX.XX.XX",
  "json": null,
  "files": {},
  "args": {}
}

If you’re seeing content-length of 0, then your BRS may not be sending any POST data. If I do this…

  port = CreateObject("roMessagePort")
  xfer = CreateObject("roURLTransfer")
  xfer.SetPort(port)
  xfer.SetURL("http://192.168.1.105/echo.php")
  xfer.AddHeader("Content-Type","application/x-www-form-urlencoded")
  if xfer.AsyncPostFromString("fubar")
    msg = Wait(0, port)
    
    if type(msg) = "roUrlEvent"
      ? msg.GetString()
    end if
  end if

I get back this. Notice the content-length is 5, which is the length of the string I posted.

array(5) {
  ["User-Agent"]=>
  string(28) "Roku/DVP-5.2 (065.02E05040A)"
  ["Host"]=>
  string(13) "192.168.1.105"
  ["Accept"]=>
  string(3) "*/*"
  ["Content-Type"]=>
  string(33) "application/x-www-form-urlencoded"
  ["Content-Length"]=>
  string(1) "5"
}

Hey thank you Chris, That supports my growing suspicion that my post data is in the wrong place some how. If it is at all possible, could you direct your script to here: http://httpbin.org/post and see if fubar shows up in the data item & Content-Length? that would really confirm this. I would do it but was unable to make your script work (i know it couldn’t be simpler but i got an uninitialized variable error on getallheaders trying it).
I’m almost 100% sure you are right about this, but there is one sticking point - that i know the .brs is creating some sort of request body and calling it POST. I think the fact that I’m modifying code meant to send a GET request means I’m missing something somewhere. This is what the debugger shows on a failed request to twitter.

Http: # 745 done status: 400 time: 141ms request: POST https://api.twitter.com/1.1/statuses/update.json
  body: oauth_consumer_key=XXX&oauth_nonce=774729778&oauth_signature=Ahegy%XXXX%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1384529999&oauth_token=XXX&oauth_version=1.0&status=TestTweet3959

Thanks for showing me that.

{
  "form": null,
  "headers": {
    "Content-Length": "5",
    "Accept": "*/*",
    "Connection": "close",
    "Content-Type": "application/x-www-form-urlencoded",
    "User-Agent": "Roku/DVP-5.2 (065.02E05040A)",
    "Host": "httpbin.org"
  },
  "data": "fubar",
  "url": "http://httpbin.org/post",
  "origin": "---",
  "json": null,
  "files": {},
  "args": {}
}

Thank you Chris, you really helped me today. I think we’ve got it worried now.