Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
dan_shneider
Visitor

Add params to POST request body

Hey. 
In my Roko channel I am sending a POST request to our server.
Is there a way to add params to POST request body (Not the header)?
It can be a single key-value or several of them. or a json object

Thanks,
0 Kudos
18 REPLIES 18
EnTerr
Roku Guru

Re: Add params to POST request body

save to tmp:/ and then roUrlRequest.postFromFile() ?
0 Kudos
dan_shneider
Visitor

Re: Add params to POST request body

Thanks, but in this case, can you please explain how do I add header params and body params (json) to a request/file?
0 Kudos
EnTerr
Roku Guru

Re: Add params to POST request body

"dan_shneider" wrote:
Thanks, but in this case, can you please explain how do I add header params and body params (json) to a request/file?

regarding headers and cookies - that's covered in https://sdkdocs.roku.com/display/sdkdoc/ifHttpAgent
re formatting body - no, can't tell you off top of my head - but doing inspecting http in your browser (or Fiddler or packet sniffer) should put you on the right track
0 Kudos
dan_shneider
Visitor

Re: Add params to POST request body

Thanks a lot
0 Kudos
belltown
Roku Guru

Re: Add params to POST request body

To add POST params to the request body, use ifUrlTransfer.AsyncPostFromString(request), where request is a string containing your POST parameters, url-escaped, separated by ampersands. To url-escape a parameter, call ifUrlTransfer.Escape(param).
0 Kudos
EnTerr
Roku Guru

Re: Add params to POST request body

"belltown" wrote:
To add POST params to the request body, use ifUrlTransfer.AsyncPostFromString(request), where request is a string containing your POST parameters, url-escaped, separated by ampersands. To url-escape a parameter, call ifUrlTransfer.Escape(param).

Oh, my bad for glancing past *PostFromString()! (what was i thinking? probably the query string but that's part of the URL)

The non-Async version should work too, right?
Assuming one does not care about the response body (e.g. as often used as a REST action button).
0 Kudos
belltown
Roku Guru

Re: Add params to POST request body

"EnTerr" wrote:
"belltown" wrote:
To add POST params to the request body, use ifUrlTransfer.AsyncPostFromString(request), where request is a string containing your POST parameters, url-escaped, separated by ampersands. To url-escape a parameter, call ifUrlTransfer.Escape(param).

Oh, my bad for glancing past *PostFromString()! (what was i thinking? probably the query string but that's part of the URL)

The non-Async version should work too, right?
Assuming one does not care about the response body (e.g. as often used as a REST action button).

Correct, PostFromString should work too.
0 Kudos
dan_shneider
Visitor

Re: Add params to POST request body

Thank you all for your replies.
The thing is, I do need Async POST (I am using the data retrieved on the response).
My server expects several values in a json format on the request body.
I am having problems doing so.
I am creating a json string but on the request body is shows as HTML Form URL Encoded: application/x-www-form-urlencoded
This needs to be in format of application/json

stringForRequest = FormatJson(MY_JSON_STRING,1)...
request.AsyncPostFromString(stringForRequest)...

Any tips?
0 Kudos
dan_shneider
Visitor

Re: Add params to POST request body

Solved:
mRequest.AddHeader("Content-Type", "application/json")
mRequest.AddHeader("Accept", "application/json")
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.