dan_shneider
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2017
08:47 AM
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,
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,
18 REPLIES 18
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2017
10:56 AM
Re: Add params to POST request body
save to tmp:/ and then roUrlRequest.postFromFile() ?
dan_shneider
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2017
11:01 AM
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?
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2017
11:19 AM
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
dan_shneider
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2017
11:29 AM
Re: Add params to POST request body
Thanks a lot
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2017
01:49 PM
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).
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2017
02:13 PM
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).
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2017
04:46 PM
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.
dan_shneider
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2017
06:30 AM
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?
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?
dan_shneider
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2017
08:01 AM
Re: Add params to POST request body
Solved:
mRequest.AddHeader("Content-Type", "application/json")
mRequest.AddHeader("Accept", "application/json")
mRequest.AddHeader("Content-Type", "application/json")
mRequest.AddHeader("Accept", "application/json")