slingxshot
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2017
07:18 PM
roUrlTransfer send POST as JSON
I was wondering how I would send the data as JSON. If anyone has any examples.
I am trying to basically duplicate this... I am guessing this javascript sample is sending data as JSON?
var templateXHR = new XMLHttpRequest();
templateXHR.responseType = "json";
templateXHR.addEventListener("load", function() { }, false);
templateXHR.open("POST", checkIfReadyURL, true);
templateXHR.send("code="+deviceCodeResult+"&grant_type=http://oauth.net/grant_type/device/1.0&client_id=ott&client_secret=123");
Thanks!
I am trying to basically duplicate this... I am guessing this javascript sample is sending data as JSON?
var templateXHR = new XMLHttpRequest();
templateXHR.responseType = "json";
templateXHR.addEventListener("load", function() { }, false);
templateXHR.open("POST", checkIfReadyURL, true);
templateXHR.send("code="+deviceCodeResult+"&grant_type=http://oauth.net/grant_type/device/1.0&client_id=ott&client_secret=123");
Thanks!
2 REPLIES 2
tim_beynart
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2017
10:01 AM
Re: roUrlTransfer send POST as JSON
This is some edited code from a project, might be buggy, didn't test.
http = CreateObject("roUrlTransfer")
http.RetainBodyOnError(true)
messagePort = CreateObject("roMessagePort")
http.SetPort(messagePort)
http.setCertificatesFile("common:/certs/ca-bundle.crt")
http.InitClientCertificates()
http.addHeader("Some-Random-Header","header stuff")
http.SetUrl("http://something")
post = {
foo:"hello",
bar:"world"
}
postJSON = FormatJson(post)
response=""
lastresponsecode = ""
lastresponsefailurereason = ""
responseheaders = []
if http.AsyncPostFromString(postJSON) then
event = Wait(10000, http.GetPort())
if Type(event) = "roUrlEvent" Then
response = event.getString()
responseheaders = event.GetResponseHeaders()
lastresponsecode = event.GetResponseCode()
lastresponsefailurereason = event.GetFailureReason()
else if event = invalid then
http.asynccancel()
lastresponsefailurereason = "HTTP timed out. Configured Timeout: 10s"
lastresponsecode = 0
Else
? "AsyncPostFromString unknown event"
end if
end if
? "Response Headers: ";responseheaders
? "Response Code: ";lastresponsecode
? "Failure Reason: ";lastresponsefailurereason
? "Response: ";response
slingxshot
Streaming Star
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2017
01:21 PM
Re: roUrlTransfer send POST as JSON
Looks it just needed this header
response.AddHeader("content-type", "application/x-www-form-urlencoded")
Thanks
response.AddHeader("content-type", "application/x-www-form-urlencoded")
Thanks