Asked
— Edited

How To Send JSON &Amp; Set Header Request On Net.Httppost() Method?
Hi everyone, I'm using Net.hTTPPost(url, postData) method on ARC script (JavaScript). I've just realized that this method only send the body payload request as x-www-form-urlencoded. My problems are:
- How to send JSON data? I've tried JSON.stringify() but it didn't work as my expectation.
- How to set its header request? Here I attach my basic code to make a simple POST request to JSON Placeholder Fake API. I'm curious how to send JSON & how to set its header request.
var resPost = Net.hTTPPost(
"https://jsonplaceholder.typicode.com/posts",
'name=Andy&age=20'
)
print(resPost)
resPost = JSON.parse(resPost)
print(resPost.name)
print(resPost.age)
Run this code & you will see the following log in console:
> {
"name": "Andy",
"age": "20",
"id": 101
}
> Andy
> 20
Hope someone in this community can help me solve this problem. Thanks in advance.
Related Hardware EZ-B IoTiny
Related Controls
Script
EZ-Script Console
Great! there’s so much power by creating custom robot skills. And the ARC framework exposes methods that make it so easy