Asked
— Edited
How To Send JSON & 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 (view all EZB hardware)
EZ-B Iotiny
by EZ-Robot
Control IoTiny with Synthiam ARC: 100MHz Cortex‑M4 Wi‑Fi IoT/robot controller-camera, servos, ADC, I2C and digital I/O for easy internet automation
Wi-Fi / USB
Servos
8
Camera
Audio
UART
✕
I2C
ADC
✕
Digital
✕
Related Robot Skills (view all robot skills)
Script
by Synthiam
Multi-language ARC Script: build, run and debug Blockly, JavaScript, EZ-Script or Python with Intellisense, run/save/load and Roboscratch support
EZ-Script Console
by Synthiam
Real-time EZ-Script console for ARC: enter and execute single-line commands, view output, clear display, and recall history with UP/DOWN.

Great! there’s so much power by creating custom robot skills. And the ARC framework exposes methods that make it so easy