Anish1
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017
12:26 AM
Re: Add params to POST request body
could you show the code you wrote for this issue to resolve......because i have been through the same problem...thanks in advance...
tim_beynart
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017
04:12 AM
Re: Add params to POST request body
Using JSON formatting functions will not work, you have to generate your POST JSON manually using Chr(34) to insert the quotation marks.
Value1="some value"
Value2="some other value"
post="{"+Chr(34)+"Key1"+Chr(34)+":"+Chr(34)+Value1+Chr(34)+","+Chr(34)+"Key2"+Chr(34)+":"+Chr(34)+Value2+Chr(34)+"}"
If http.AsyncPostFromString(post) Then
event = Wait(timeout, http.GetPort())
If Type(event) = "roUrlEvent" Then
response = event.GetString()
Else If event = invalid Then
? "AsyncPostFromString timeout"
http.AsyncCancel()
Else
? "AsyncPostFromString unknown event", event
End If
End If
if response <> invalid AND response <> ""
json = parseJSON(response)


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2017
01:03 PM
Re: Add params to POST request body
"tim_beynart" wrote:
Using JSON formatting functions will not work, you have to generate your POST JSON manually using Chr(34) to insert the quotation marks.
Tim, can you be more specific about what is not working for you?
Certainly, you do not have to manually format JSON in the general case.
The only problem I can guess that you are running into is with respect to associative array key case preservation,
which might be an issue if you are assigning fields using a.Key=Value instead of a["Key"]=Value or a.AddReplace("Key", Value).
Value1="some value"
Value2="some other value"
a={}
a["Key1"]=Value1
a["Key2"]=Value2
? FormatJSON(a)
'==>
{"Key1":"some value","Key2":"some other value"}
tim_beynart
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2017
11:49 AM
Re: Add params to POST request body
Tim, can you be more specific about what is not working for you?
Certainly, you do not have to manually format JSON in the general case.
It's been quite some time since I messed with it, but IIRC, my request body was blank if I tried to use an AA converted to JSON using formatJSON. The case is not an issue, I wrote that example off the top of my head. I can try to dig up an example to demonstrate.


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017
06:04 PM
Re: Add params to POST request body
"tim_beynart" wrote:
It's been quite some time since I messed with it, but IIRC, my request body was blank if I tried to use an AA converted to JSON using formatJSON. The case is not an issue, I wrote that example off the top of my head. I can try to dig up an example to demonstrate.
As another attempt at psychic debugging, I'm guessing that your call to FormatJSON was failing and returning an empty string.
This doesn't have anything to do with the roUrlTransfer or POST part of your code, but could happen if you had non-POD (plain old data) values in the AA, for example, or something that was not directly supported by JSON.
I would expect that you would see an error message printed in the app debug console in that case.
https://sdkdocs.roku.com/display/sdkdoc ... 0asInteger)asString
Hope that helps. 🙂
parag
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2017
11:24 AM
Re: Add params to POST request body
I have the same question. I have a request with a bunch of query params that I am try to post and I get a request timeout with everything that I have tried.
url = CreateObject("roUrlTransfer")
1. url.SetUrl("http://www.google.com/tesing?userId=test1&sessionId=test2&categoryId=test3")
2. url.SetUrl("http://www.google.com/testing")
request=url.Escape("userId=test1&sessionId=test2&categoryId=test3")
3. a = {}
a["userId"]="test1"
a["sessionId"]="test2"
a["categoryId"]="test3"
request=url.Escape(FormatJson(a))
url.AsyncPostFromString(request) in #2 and #3 and url.AsyncGetToString() in #1 all return a -7 response code. Any pointers to what I am doing wrong here? A rest client gives a response with both post/get.
url = CreateObject("roUrlTransfer")
1. url.SetUrl("http://www.google.com/tesing?userId=test1&sessionId=test2&categoryId=test3")
2. url.SetUrl("http://www.google.com/testing")
request=url.Escape("userId=test1&sessionId=test2&categoryId=test3")
3. a = {}
a["userId"]="test1"
a["sessionId"]="test2"
a["categoryId"]="test3"
request=url.Escape(FormatJson(a))
url.AsyncPostFromString(request) in #2 and #3 and url.AsyncGetToString() in #1 all return a -7 response code. Any pointers to what I am doing wrong here? A rest client gives a response with both post/get.
NB_
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2017
03:28 PM
Re: Add params to POST request body
Your issue is encoding the full string, where & and = should be as-is. Something like this should do it (typed but not tested):
when called with your
function params_to_query_string(params)
lst = []
for each item in params.items():
lst.push(item.key.escape() + "=" + item.value.escape())
next
return lst.join("&")
end function
when called with your
a = {
userId: "test1"
sessionId: "test2"
categoryId: "test3"
}
parag
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2017
06:55 AM
Re: Add params to POST request body
Thank you.
aleemaheer
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2023
10:07 PM
Re: Add params to POST request body
Still I can't understand how to send body in post request
- « Previous
-
- 1
- 2
- Next »